Large ship engines can be on the order of 10,000-30,000 hp or more. In KW that's 7.5-22MW.
A large cargo ship might be Panamax (https://en.wikipedia.org/wiki/Panamax) and thus 950ft long and 105ft wide or have a total top surface area of 99750 sqft. Commercially available solar panels have an efficiency of around 20% and sunlight is often quoted as 100w/sqft so you might be able to generate 2MW of electricity from covering the entire top of the ship in solar panels. 2MW compared with say 15MW is significant but there are problems.
That's for a flat array, not something that tilts. So you're only going to get about 6hrs of full power output per day, assuming good weather. Now your 2MW drops to only 500kW of average power or lower.
And those panels are going to cost at least $0.50/watt or something like a million dollars, nevermind mounting, inverters, cabling, etc. Could easily triple the price there. Plus the sea is rough on everything. If the panels are rated for 30 years on land you should expect to get less than 10 years at sea, maybe less.
Finally the assumption that you can simply cover the top of a ship with no repercussions isn't necessarily true. For tankers and bulk carriers you might get away with it. But on container ships you'd have to figure out how to make the entire array fold away since these ships are top loaded and unloaded. https://thumbs.dreamstime.com/z/container-cargo-cranes-unloa...
The idea makes sense if you don't know the magnitudes of things. But once you do it starts to look less practical.