Sometimes you getting that when i guess the traffic data is to big or you hit the site reload button and acting to fast.
There are at some stage some breaks but normaly it should be working with in a few minutes after you getting the message for bad gateway.
It also can be something have to do with cloudflare , sometimes.
You should be not worried about it.
I guess your first paragraph best explains it. I've also encountered that several times though my first time experience was hysterical. I panicked. It went from me thinking someone had hijacked my account to thinking the forum had suddenly disappeared (as in, dumped by the admins/owner). With time (each time it came up again) I realized either of the two you mentioned could be the most reoccurring cause for that. This day when I encounter such I just close the site and wait a few minutes before trying again. So far, it has worked wonders because there's nothing much to it to bother anyone.
Theymos once answered on a thread on the same topic:
It was a DDoS attack.
Check the date on theymos' post and what it was addressed to, you would realized that both situations aren't the same.