Why it broke would take some forensic examination. Anything from over tightened sometime in the past to rust propagation.
How to repair, remove the hub (lockout, wheel bearings).use a drift and punch the old one in. Don't do this until the hub is off because if you have to move it with a chunk of lug rolling around inside the brake drum things can self destruct in a fraction of a turn of the wheel. New stud goes in from the back side. Press in or hammer/drift it in. Do NOT use the lugnut to pull it in, you will overstress the stud pulling it in. Consider doing the others since you have it this far apart already. Put it all back together.