Bath fans need roof vents because they carry moisture and germs as well as smells out of the bathroom. Fans that ventilate into an attic release that moisture into that closed-off space, encouraging the growth of mold and mildew. Venting through a roof vent eliminates the problem.
Venting a fan into the walls also increases the possibility of mold growth, either in the pockets of the wood or within the fiberglass insulation batting. Once mold takes root inside a home, it can be toxic and must be removed by specially trained professionals.
Options for venting bathroom fans include running the exhaust pipe to the roof, through a sidewall or down through the soffit vent. Soffit vents are placed around the roof's perimeter, under the eaves. They work in concert with ridge line and other vents to improve attic air flow. There are several, so fitting one with bath fan duct work won't compromise the circulation in the attic.
Ductless bathroom fans are another option. They use an activated charcoal filter to freshen the air, which just recirculates into and out of the device. These work well in bathrooms where installing ductwork isn't possible, as in apartment buildings or in some vintage home restorations.