I'm builduig a ledger for indoor use (to support a work surface) with with some 2 by 4s cut to size, my question is, should I stain or paint them to protect them? for spills etc, or is staining indoor wood purely for cosmetic reasons?
A true wood stain does not build a "film" on the surface. It only changes the color of the porous wood fiber near the surface. You will want a film-forming finish if your goal is to make it easier to clean up spilled liquids. A paint will do this, but if you want to preserve the look of the wood, then 1 to 3 coats of a polyurethane based finish will also work well. Polyurethane is a clear, durable finish that is resistant to many chemicals and also to normal wear and tear.
It doesn't matter unless the room is going to have an extreme amount of humidity, temperature changes, or was subject to a lot of chemicals. What you are worried about with a ledger is warping or the bolts rusting. If I wanted to protect a piece of wood from elements I would use an oil based primer and paint as I would use in a bathroom.