Tilt shift lenses allow you to achieve "movements" - a term pioneered in the world of large format film photography. On a 4x5 or 8x10 camera with bellows, the lens itself is relatively simple and contains generally just an iris and shutter. Focus is achieved by moving that optic closer and farther from the film plane. But you can do more than just move it in/out - bellows allow you to rise/fall the lens parallel to the film plane or shift it sideways or swing it sideways or tilt it up/down - and bellows allow you to do all these things at once. Or you can leave the lens in place and rise/fall/shift/swing/tilt the film plane itself. The tilt/shift lens is a method to achieve some of these movements on cameras without bellows.
These lenses work because the optics cover an area much larger than the sensor/film size of the camera they're intended for. To picture what a Tilt/shift lens is doing, imagine that the lens projects a circular image the size of a round paper plate. Inside that paper plate is a 3x5 notecard which represents your sensor/film. Sliding that paper plate around on top of the notecard you're choosing that portion of the projected image. That's what's happening with a shift/rise/fall.
Imagine pointing your camera on a wide-angle lens at a tall building. If you aim level, you'll likely cut off the top of the building. If you tilt your entire camera up you'll frame it in, but you'll exaggerate the "keystoning" of the building or the appearance of the sides of the building angling together at the top. An architectural photographer (or Stanley Kubrick for example) may not want those lines to converge and may prefer that door frames, corners etc all remain perfectly upright. The power of the rise/fall movement is being able to keep the camera level and rise the lens itself upward to frame-in the top of the building without changing the geometry of the room. Very cool. Or conversely - you could "fall" the lens to trim your frame for headroom without tilting the camera down. It's a cool and subtle effect. Spin that on its side and do a horizontal shift, and now it's as though you're standing a bit farther to the side than you are. Useful way to shoot into mirrors without seeing yourself.
Tilting is a different story and most of what you're seeing when people use TS/E lenses for effect is because of tilting the lens in relation to the focal plane. The math behind tilting is called the Scheimpflug principle. Basically your plane of focus is no longer parallel to the sensor/film, and you can choose what angle your plane of focus falls. Meaning - you can shoot someone walking towards you from some distance away and if you choose their path and the plane correctly, you won't have to pull focus because they'll be sharp the whole time. The rest of the scene may look crazy but they'll be sharp. Or you could aim straight down a long road and have the entire road be in focus.
There's a lot more to TS/E lenses than just that "fake miniature" effect, and knowing that these tools exist can be super helpful for those few times when you're in a head-scratching situation.