Why is there swelling if a bone fractures?

Soft tissue injury. When bones fracture they release a large amount of energy into the soft tissue around them which damages that tissue. In addition swelling also occurs as part of the healing response as blood flow increases to the area around the broken bone which also causes swelling.
See below. Due to the trauma there is swelling of the surrounding tissue. The swelling is a reaction to the fracture.