To simplify the situation: each and every one of the keys is given each of the letter names A to G. In C, with no # or b, they are C D E F G A B. The spacing between each two letter names is T,T,S,T,T,T,S where T=one tone, S= a semitone. That's what we decided sounds o.k. a long time ago. So, C>D=T, D>E=T, E>F=S, etc.It must work for all major keys, in 12EDO (equal tuning). One main reason for this naming procedure is that when music is written out, each letter name needs its own line or space.
So far so good, I hope.Getting on to your B key - the letter names will be B C D E F G A. EXCEPT that to get the spacings correct, # OR b need to be applied.Starting on B, the next note up is a C - of some sort. There needs to be a spacing of one tone from it, so the next note is called C#. From there, it's another tone, we're onto letter D, so it's D#. Next, one semitone away, is plain old E.
Now, it's clear that if the 3rd note (D#) was to be called Eb, there is a problem. In this scale/key, there are TWO notes that we'd call E (Eb and E). Writing it out, they'd both be on the same line/space, and there'd be a lot of cancellation of one for the other. And a lot of confusion, alleviated by calling the 3rd of the key of B D# (which wouldn't otherwise ever have a note written in its own place!)
The same applies for each and every note of each and every key, and although complicated, actually simplifies the situation. Guitarists, from experience, don't seem to have a problem calling a note by either name, but technically in one key there's only one proper name, and in the heat of the moment, it's academic, and only becomes problematic when trying to write the music for others to read.
And that's the simple explanation...
This idea happens in each key,which is why C has no #/b, A has 3#, Eb has 3b, etc.
Your parting question - a note such as F# features in ALL of the major key signatures, therefore it will be far more commonly called that rather than Gb. In the same vein, Bb comes in every flat key (F, Bb, Eb, Ab...) so is far more likely to be met as such rather than its alias of A#.