This answer is going to be a bit of a guess. I've noticed that when playing drums I have almost the opposite problem: when I'm playing, I'll sit up straight, but when I'm just sitting on the stool, waiting while the rest of the band faffs about, I'll often hunch down, resting my chin on my hands and my elbows on my knees or the rim of the snare drum. For this reason, I suspect that kit set-up is a big factor.
I play with sheet music and a conductor, so my music stand is set between me and the conductor. If I'm sitting upright, the conductor is just above the stand, but if I start slouching, he disappears behind the stand, so it's an immediate reminder to sit up. If you're rehearsing in a group, you might be able to arrange something similar with another player you need to look at. Even if you're on your own, you could do the reverse: have a light pointing in your face with a card in front of it, so that if you're upright, the card shields your eyes, but if you start to sink on your stool, you get dazzled.
You might also try raising your ride cymbal. Jazz players tend to have the ride very low, whereas rock drummers often have it up at the same level as other cymbals. If your ride is low, then for a tight passage you'll instinctively hunch to get closer to it, but if it's higher up (but still below shoulder height), you'll naturally straighten up to avoid having to lift your arm so much.
At the same time, try moving your snare drum height. This is very much down to personal preference, but you might find that a change makes it harder to lapse into the old slouching behaviour. Just make sure you're sitting upright when you set and try out the height!
Since you already know the postural change you want to bring about, and the difficulty is in breaking your old habit, I can also recommend a technique from other fields, which should work whatever instrument you're playing.
There's a device variously known as a "mindfulness bell" or "experience sampler". It's a keyring-sized gizmo or smartphone app, which you keep in a pocket, and it bleeps or vibrates at random intervals (say, two or three times an hour). Buddhists use it all day as an occasional reminder to be mindful and aware; it's also used in scientific experiments in real-world settings to prompt the subject to note down some item of interest at random points during the day, such as what they're doing or their mental state.
You could use it while playing as a reminder to focus on your posture. I wouldn't try it while performing, but during a long solo or group practice, it shouldn't disrupt your concentration too much. You might also find you keep it for other parts of your day where you might lapse into old habits.