That question is a bit difficult to answer as there's no real way to document when the first instance of the Star Spangled Banner being played prior to, or during, an athletic event was.
Having said that, it seems to have started with baseball, and that seems to go almost all the way back to the early game, as an occasional, but not routine, occurrence. There are examples of it taking place in the 19th Century. A well known 20th Century example was during one of the games of the 1918 World Series, but that was actually during the the seventh inning stretch of one of the games that year. Woodrow Wilson had issued an order (not that it would apply to baseball, of course) that it be played at appropriate occasions somewhat earlier and therefore the playing of it, during World War One, was something that was occurring in any event.
The Star Spangled Banner itself didn't become the official National Anthem until 1931. Playing the National Anthem at baseball games became the norm during World War Two. That spread to professional football quite rapidly, although it might be worth noting that professional football was nowhere near the big deal in American sports that it now is.
Following the war it stuck and football Commissioner Elmer Layden expressed the opinion that it should continue to be the norm (see Pigskin: The Early Years of Professional Football). When it spread beyond football and baseball I don't know. The NFL has a rule requiring it to be played prior to each game, but I don't know when that was adopted.