Hanging Notes
The MIDI protocol is an amazing survivor in the world of computers. Though to be fair, its contemporaries are the CD, Microsoft Word and the Apple Lisa.
The underlying spec that was adopted at the start (c1983) has not changed significantly since - it's been expanded a bit, but the way notes are played is just the same.
This does mean the possibility of 'hanging notes' in MIDI has also been passed down the years to us. MIDI should be about a NoteOn message being sent, shortly followed by a NoteOff message. But sometimes, for whatever reason, they get separated. Then the keyboard or synthesizer will keep playing those notes until someone tells it to stop. As well as any other notes that arrive in the meantime.
This is the time for a Midi Panic message - stop everything you are doing.
How to stop them
To make a keyboard go silent, unplug the USB cable from the Raspberry Pi, allow Box Of Stops a moment to detect this (10 seconds is plenty), and plug it back it.
Whenever Box Of Stops detects a new device, the first thing it does is send a Midi Panic, or Stop All Notes, message to it. For anything to work with Midi, the controller (Box Of Stops) and the synthesizer (or keyboard) need to agree over which notes are playing. Box Of Stops is just making sure that both ends agree on that being no notes at the start.