...which is precisely why having the Science and Engineering Officers as 2nd and 3rd in line is a big problem. I'm not a seaman or mariner, but I doubt they ever do that on real ships.
Why would it be a problem? It happens all the time in the US Navy (for engineering anyway, there aren't real "science officers"). Almost all USN line officers serve in a ship's engineering department at some point in their careers, and many warship captains served as chief engineers for their department head tour. For submarine captains, it's more like 100%.
Even in the age of sail, naval officers were trained in mathematics and "scientific" disciplines like astronomy, for navigation. Later specialties broadened to include highly technical fields like steam propulsion, fire control, torpedoes, electricity and radio, and today it might be missile guidance systems or computer networks. None of which interfered with the officer's training for eventual command. As a lieutenant, Admiral Nimitz of WW2 fame was one of the top diesel engine experts in the US and had private sector offers of many times his navy salary.
I don't see a problem with officers' specialization in a space-exploring service expanding to include even "hard" science, or a Starfleet officer working in a ship's science or engineering departments and still being in line of command. And, it fits what we've seen with Spock, Scotty, Sulu, Will Decker and maybe even Kirk (it seemed like he may have been an engineering watch officer as an ensign from what was said in "Court Martial").