Initially the reason they're there is because Star Wars is a Space Opera, which is an sub-genre that mixes sci-fi with fantasy to include magic-like elements and fantasy-like story plots.
Lightsabers were also meant to be the de-facto weapon, with early concept art showing stormtroopers (including light shields),…