While the exact origin is unclear, it likely emerged as a more informal and humorous way to talk about something that can be unpleasant or even embarrassing. It may have been influenced by similar slang terms for phlegm, like "gunk" or "snot."
"Loogy" is considered informal and should be used with caution, particularly in formal settings.