In the 1800s, on the battlefield, when the medics are performing painful operations on wounded souldiers they used to give the subject a bullet to bite as a way of dealing with the pain. Hence, this idiom, meaning to toughen up and accept the pain.

Note: Lead bullets are poisonous so you shouldn't bite them and any other type would probably be too hard to bite.