As Matt Colville says, "Rollercoasters are on railroads, and people seem to like those!"
I'm going to paraphrase his quite good video on the subject, but essentially there are two types of railroading.
"Good" Railroading
There is "railroading" where there is essentially a set plot the DM has set up, with a series of encounters that progress in a linear manner. You first do A, then B, then C... you can't move on to B before completing A, etc.
There's nothing really wrong with this; in fact, most modules are constructed in exactly this way. Now, although each encounter needs to be completed in a linear way, that doesn't mean they have to done in a specific way exactly the same every time. It's why two different groups can play the same linear module and yet have completely different gaming experiences.
Three different groups, playing the same adventure, need to get a key from the guard to escape. The first group tricks the guard into entering the cell, they beat him up and take the key to escape. The second group talk to the guard, gaining his sympathy and convincing him to escape. The third group waits for him to nod off to sleep, and use mage hand to swipe the key and escape. Very different methods, same result.
This is railroading in that the same events all need to happen to progress, but how the PCs do it is allowed to be very different; so yes, they're on a railroad, but the PCs still have plenty of choice, and they still have tons of fun! Players often like having plot points and hooks fed to them directly, but they like using their own methods to move forward.
"Bad" Railroading
Bad railroading takes all the above, but with one step further. Not only are the events linear as above, but there is only one solution to every problem. There is no player choice, as the DM will only allow one specific solution to solve the problems they lay before the players. Essentially, the PCs must follow the DMs script. If this encounter is supposed to be a fight, the PCs can't negotiate a peaceful solution (or vice-versa). It doesn't matter how high the PCs roll, or how creative their solutions, the DM will find some reason it fails and drive them back to their scripted solution.
To use the prison example again, the DM has it written down that the PCs need to wait for the guard to fall asleep, and then use mage hand to take the keys. But groups 1 and 2 are impatient (and have no idea the guard is going to fall asleep eventually). Group 1 tries again and again to trick the guard, but none of it works; even when they roll well, the DM argues that this guard is especially smart and won't fall for such tricks. Group 2 tries talking to this guard and explaining their situation, hoping to win them on their side; even when getting a natural 20, the guard has no interest in helping them.
This is bad, because there is no choice at all. It's like watching a movie (or being an actor in a movie) where the director has given you your lines, and you're meant to follow them. Sometimes that's fun, but it's not really D&D either.