Just send them a message in slack. Don't be so obnoxious as to assume that whatever's bugging you at this moment is automatically more important than whatever your co-worker is on.
I don't know why it feels weirder to slack them then it does to turn your head and ask. One demands immediate attention, the other allows them to answer when they have bandwidth for it. It seems obvious enough to me which is more polite.
In practice it doesn't pan out that way, because most 5 minute questions don't save that much time (answer was a 2 minute search away), don't take that much time (take much longer), and overall cost much more time (due to loss of flow).
Most (if not all) programmers need a state of flow to write quality code. Achieving flow after an interruption can easily take 15 minutes or more. If the environment discourages a state of flow by having frequent brief interruptions, the quality of the code written in that environment will be poor. If you had the ability to collect the right metrics, you'd probably find that bugs disproportionately are written right after an interruption.
The other issue you raised is that sure, your productivity may go up if you interrupt someone and get a question. It's clear that we don't want to optimize for that, because the interruption may cause someone else a loss of 30 minutes before they get back into the zone. It's not just 5 minutes. And 20 minutes into that recovery of concentration, someone else will interrupt them and ask another question. And they will also interrupt you. That creates a very frustrating experience. So it's better to ask your question asynchronously. You will get your answer when the person takes a break and relaxes their concentration. Both of you will be able to exercise control over when you can concentrate on getting your work done. Having that sense of control and ability to concentrate is critical to being productive.
I basically think it disturbs more with questions in an open space than when you go over to a cubicle/room.
Lets say that you have a 5 minute question, that would save you an hour of work.
In a closed/cubicle style office, you may be less willing to bug your expert co-worker. In an open office, it may be perfectly normal to turn to your left, and quickly ask you question.
Sure, you are taking time out of your co-worker's day, but even so, on the net whole, asking the question is probably a net benefit time saver to the company.
In closed-style offices, it is a big gesture to walk into someone's office and ask a question. I'd feel less comfortable doing that.
Even sending a slack message still feels less comfortable than just turning your head and asking a quick question.
Coding is a collaborative process to many people. I don't want to schedule a freaking meeting for my simple question, or walk into someone's office. I'd probably just not ask if I felt like I was bothering someone.