First of all, you can make any transformations you like in both Newtonian physics and Maxwell theory. The key idea is principle of relativity, which states that inertial frames are all equivalent and cannot be distinguished by any experiment.
Back then physicists knew about 2 kinds of interactions - Electromagnetic as described by Maxwell theory and Gravitation as described by Newton theory. Relativity principle when combined with appropriate theory gives you how time and distances need to transform when seen from two different inertial frames. What this means is that you need to make definition of time and space in such a way, to make the transformations work. This was not obvious from the start, but after a time and after a lot of research and it culminated in Einsteins finally realizing this point.
Now gravitational theory was seen as "bad" from the start. Even Newton himself was dissatisfied with the "spooky action at a distance". The force produced by Sun is just instantaneously transmitted on the planets without any mechanism of how is it doing it. On the other hand, Maxwell theory was beautiful, there was some field and the interaction propagated from point to point with some speed, when the change of field only produced change in its immediate neighborhood, just like waves are propagated on a water. No spooky action at a distance.
So Maxwell theory was of course preferred over gravitation.
But of course, the Galilean transformations are just common sense. Moreover, the analogy between waves on water and light waves was too good to leave and the field was by many believed to have some material existence. So it was only natural, that physicists first idea back then was that there must be some substance in which these fields live and in which the light propagates. It was not weird, that principle of relativity does not hold anymore for Maxwell theory, as this theory is just attached to this mysterious substance. Just like waves on water do not obey relativity, simply because the water itself is creating preferred frame of reference.
And just like water creates special frame of reference, so does this mysterious substance called eather. The thing to do now, is to find this preferred frame of reference and Michelson-Morley experiment was devised. They did not find any preferred frame of reference. The first idea was that eather is somehow dragged by the movement of Earth. That would explain the negative result, but the explanation was unsatisfactory. What material is dragged by motion of planets, yet does not produce any drag on the planets themselves?
The better idea was searched and was found by Lorentz, Fitzgeral and others. They thought, that because EM field generated by charge is different based on its movement, this change in field itself has consequences on our measuring apparatus - on our clocks and meter sticks. This makes sense, if our metersticks and clocks work on the EM principle. We know they do, as EM is the only interaction except gravitation relevant on human scales. In a way, as EM field is different when meterstick is moving, the forces between molecules are also different and meterstick gets contracted. Lorentz developed this theory and it turned out, that metersticks and clocks get deformed in just the way to make any attempt at finding this preferred frame futile. So the principle of relativity really creeped back in in a very indirect and not very obvious way.
Now comes in Einstein. Einstein was fan of both principle of relativity and Maxwell theory and he had the revolutionary idea that why don't we just define time and space according to what we measure? Ok, it was not as revolutionary, the science was already doing that a lot and positivism was quite influential school of philosophical thought. Especially Ernst Mach, which influenced Einstein quite a lot, is known for his critiques of mechanics in this direction. So the ground was already sat for Einstein to start moving in the right direction. And it is only here, where the abandomnent of galilean transformations arouse by the sheer decision of defining time and space according to our measurement process and not according to our predefined ideas.
But how to make the new definition of time and space to make sense and how to understand it? Einstein simply analyzed what does measuring time and measuring distance really mean. He found out, that there is common denominator which is simultaneity. You simply need to know which events are simultaneous to measure distances and to compare clocks. But how to decide which events are simultaneous? If lorentz theory is to be believed (and gravitation theory not), then the only sensible way to define simultaneity is by using the fact that light is always measured to have the same speed. And from this all follows.