It's policy on campus here:
Can I bring bicycles into campus buildings?
No, all bicycles must be stored in the bicycle racks located outside of buildings. Owners storing their bicycles anywhere else are subject to a fine.
There are plenty of bicycles here. I occasionally violated that rule but my building is so seldom frequented that nobody complained. If I was walking my bike through a major hallway and campus security saw me, I would fully expect to be told not to bring my bike inside. The policy might exist for a practical reason, and while it isn't applicable all the time, it should probably be enforced equally and fairly. If it is school policy (like it is here) then the security guard was just doing his job.