In the macOS Terminal, my mouse scroll wheel would magically start scrolling the command line history instead of the window buffer scroll bar on the right to show window history. This happened when an SSH session was disconnected or timed out. The fix is to run the reset command.
I stumbled onto this link about the world’s most beautiful castles and I took some of the pictures to show here. Click here for the original article with excellent descriptions.