Good question, and Beyonce is grammatically correct! (Unlike Gwen Stefani's "If I Was a Rich Girl", which is sloppy grammar.)
Although "were" is a plural of "was", it also is used for unreal, imagined or hypothetical situations in the past. That is, things that never happened.
For example, the correct form is "I wish I were taller." If you write "...I was taller...", that means it actually happened and you had become shorter since.
And for Beyonce, if she had sung "If I was a boy", that means that she actually was a boy in the past. Using "if" in the sentence just adds to the confusion. "If I were a boy" means she isn't a boy, never was a boy, and she can only imagine the situation.