a simple theory...
a lot of guys change the lights of their corollas and civics... now the new lights are also of the same car but modified... so thats legal cuz thats ricing up the car
similarly a more revelent example of your case... what if 1 meets an accident and needs to change the hood, bumper, lights and front grill? what would you call it? ilegal? i dont think so...
your old body got rusted and weak so u changed it with a new body. chassis remains the same, engine swap is already legal thus the whole thing makes it completely legal...
it'll be ilegal if you drive a number two car with its original chassis and engine and put the number plates of your car on that... now that'll be ilegal cuz the chassis number on the book and the car are not the same...
hope it clears some confusion