It means that the speaker can't reasonably explain events, and vacates their critical faculties to invoke what they conceive as a "higher authority".
what does it mean when someone says that only God knows why things happen? What are they referring to? Can someone please tell me. Thank you.
It means, in a sense, that everything happens for a reason.
They are implicityly acknowledging that only an eternal, omnipotent God could possibly have the perspective to see how all things that happen in this temporal world are related to the eternal world of which we are a part---and thus know "why."
They don't know or it's a believing of the religion, it's a phrase of the believers.