Here is a link to the FIDE record for a norm tournament where I was the chief arbiter. Two or three lines up from the bottom it says "PGN file" and next to it is a brownish icon. If you click on it you can see a list of all the games with the possibility to play through them in a PGN viewer or to download them.
Here is a link to a low level (Minor) tournament I played in a few weeks ago. Towards the bottom of the header it says "Games: There are 59 games available for download". Clicking on the link gives you options to download games by round or to download all the entered games for the tournament.
These games have been entered and uploaded by arbiters and their assistants (cue for you to say "Thank you, arbiters!"). Some of this work (norm events) is done because it is a FIDE requirement. Some of it (like the low level tournament I played in) is done out of the goodness of the arbiters' hearts.
Generally speaking if you enter a tournament and the scoresheets provided are single copy then your game won't end up in an online database and if it is a two-copy scoresheet then it will. The two-copy scoresheets cost more and a tournament organiser would not waste money on them unless the games were to be recorded and uploaded.
People who run websites that include all the games they can find have written bots which crawl the web (or at least select parts of it) looking for PGNs which they download and add to their collection for their website or database.