Anyone can join in on Raids as long as the Group Raiding don’t select Private Battle which will exclude randoms from joining in with them. Most groups gathered around a Gym for a Raid are usually accommodating.
There’s been the odd case reported on here of unfriendly snobs excluding people. The worst case I’ve herd recently was where the Group of Raiders sabotaged the Raid by not fighting and only dodging than jumped out of the Raid and took off leaving not enough left in the battle to defeat the Raid Boss.
Just rock up and ask if you can join in.