Experiments are at the heart of physics. We conduct experiments to find the values of certain constants, to disprove certain theories, or to gather evidence in favour of certain theories, or to refine theories so that they become consistent with other theories. Some experiments are however, very hard to do, because of the expense involved, or because some ideas are just too big to be born whole, or because the best way to plan an experiment is to think about first. There is no cheaper, quicker place to start experiments than in our own heads, and in this way a thought experiment can be a precursor to an experiment that is later performed.
Aristotle thought heavy things should fall faster than light ones. He thought a stone should fall faster than a feather. So Galileo said, "Let's glue a feather to a stone and drop it. Together, they weigh more than either the feather or the stone alone. If Aristotle's right, they'll fall faster together than either would fall alone. But who could believe the feather wouldn't slow the stone? Aristotle has to be wrong."
That's what we call a thought experiment. Galileo did the experiment in his head. Ernst Mach thought up a rationale.. He said intuition is accurate because evolution has shaped it. We shrink from the absurd. That's what Galileo was doing when he said a feather can't speed the fall of a stone. Many thought experiments try to arrive at a ridiculous and impossible conclusion in this way, analogous to proof by contradiction in Maths.
Enter now the grand master of thought experiments, Albert Einstein. Einstein a disciple of Mach. He created a great theatre of thought experiments to derive and explain relativity, reconciling in the process, the theories of electromagnetism and much of Newtonian mechanics, with adaptations. Thought experiments were necessary because at the time there were no obvious experiments that could be done. . He talked about throwing balls and reading clocks on railroad trains and elevators. His conclusions had nothing to do with intuition.
Quantum physics especially gives rise to many thought experiments, because the foundations of quantum physics are often unclear and open to argument. Many quantum physics observations are counterintuitive, and thought experiments are used to refine the basics of quantum physics, especially wave particle duality, the 'ghostly action at a distance' nature of entangled particles. There has been a thought experiment done that implies that no alternative to quantum physics is actually possible, and these sort of experiments are dreamt up constantly to refine the foundations of quantum mechanics.