“Happen to know” is used when the speaker is unsure that the listener has any knowledge of a subject. The speaker is often asking a question in this manner when they feel that there is a low probability of receiving an answer and wants the listener to know that it is ok if they don’t know.
Do you happen to know when the next bus arrives?
Do you happen to know where to get tokens for this machine?
What is the difference between “Do you know?” and “Do you happen to know?”?
“Do you know?” is a more direct question which means if someone has a particular piece of knowledge. “Do you happen to know?” has the same meaning but may be used in a slightly different more nuanced situation.
I think that people often use “Do you happen to know?” when they are approaching a stranger and they want to use a more indirect question to give the stranger more time to process the question when there is no preceding context. We often use indirect questions in this way to avoid coming across as rude.