Welcome to evolution.
Just because the idea is great, the path obvious (in our minds), does not mean it will happen.
Evolution works by random mutations followed by selection to weed out nearly all phenotypes that are less successful than the original.
So you need both the mutations and right selection environment.
So while gills on a sea going mammals is a great idea. The path towards that is not an easy outcome without some form of intelligent design. You see those gills arches fishes have to support their gills... well the tetrapod lineage has since re-purpose those bones to make several structures such as the thyroid gland, part of the jaw, the larynx, and the bones in mammalian ear. https://en.wikipedia.org/wiki/Branchial_arch
So a whale that simply reconverts to gills, would be without a larynx (mute), or inner ear (bad hearing) and parts of the jaw (Can't eat). So you can see alot of other work will need to be done to make such an animal work. And if this process is left to nature, each intermediate must also work successfully in some environment.
Such are the constrains of evolution.
However if intelligent design were available. No problem. It can be done. We can ignore temporary lowered fitness, and work with a desired outcome in mind.