There are a number of problems.
Firstly there is a different mechanism for calculating price for ships on and the ship you have. One difference is that for new ships, equipment is discounted 10%, the players equipment is not (adding the same discount to player equipment was the change I mentioned above).
It is possible, but not a complete solution to simply cap trade in prices. This makes profit much harder, but does not fix the underlying problems.
Other issues related to the calculations include things like equipment from oxps -- I dont think (need to check the code) that some stuff like rock hermit detectors are included in the price calc. Im also not too clear about if you get your money back for missiles and mines and so on.
It also make sense for shipyards to charge a premium of some kind, like auto traders, they buy a car for $100, and sell it for $150. At the moment this is set to 25%, which makes it hard to profit from ship trading, but it remains possible. Or, if you want to look at it another way, there is 25% sales tax on ships.
Allowing a commander to keep items might be ok, but there are issues related to which items can be fitted to which ships -- not all combinations are allowed. There is also a tech level question of sorts, if the tech level isnt high enough for a bit of kit, then its not clear that they would be able to remove and refit the gear to your new ship. Maybe they will refuse to pay you for high tech gear, or maybe they pay a premium?
Edit: good point from Commander McLane, who can clearly write more succinctly than me
just because many ships can fit the same thing for the same price, does not mean they are interchangeable. A cobra docking computer costs the same as a python one, but they are different things. Like cell phone chargers, they are all about $25 dollars, but good luck fitting a nokia charger to an ericsonn.
Some gear is always kept already though, if its awarded through a mission I think. This is even more confusing, because it should not be reflected in the price you get when you sell the ship. Perhaps for equip that must be removed and refitted to the new ship, there should be a shipyard fee?
And one of the interesting problems with buying a new ship, is that you sometimes find the ship of your dreams, but because of the tech level, you have to take it somewhere to be fitted out, this adds risk (I have to fly through 3 anarchies before I can fit a beam laser? maybe Ill pass), and makes buying ships more interesting.
An alternative view is that allowing a player to buy cheap ships at high tech worlds, fit them up with top quality gear, and sell them for a profit at a low tech world is in fact an entirely reasonable business to allow players to be in. Its just like buying and selling used cars. I dont think I really like it, but its not so bad.
So, its not simple, we do need to have more thoughts on it. A good starting point would be to get the code easier to work with, which is what I was hoping to do, but for the moment have given up, because I dont know what oxps might get broken.