The story
From in before. It originated on 4chan: on threads that users thought would be locked, they would comment "in before the lock", or "I got a comment in before the thread locked." Before then got abbreviated independently into B4 or b4.
Etymology from Wiktionary, CC BY-SA 4.0.