You might as well ask this of most spaceship designs in any science fiction work, it's not specific to Star Wars at all.
However, there is a very simple reason and one you have overlooked.
Whilst Star Wars as a whole plays with physics, most spaceships do have to fly in a planet's atmosphere.
We see them going in and out of planets all the time and even flying and fighting inside of them.
For example, at the Battle of Takonda in
The Force Awakens we see X-wings and TIE Fighters in the atmosphere fighting.
Wings are beneficial here.
scifi.stackexchange.com/users/58193/TheLethalCarrot
Another factor is weapon placement.
Wings or similar structures are perfect spots to put the ships weaponry to allow it to concentrate heavy firepower on the front.
A compact fighter simply doesn't have the width to mount more than 1-2 guns in most universes
(there are of course sci-fi universes where weapons don't take up a lot of space), so having another 2-4 guns on the wings allows the fighter to bring more firepower to bear while keeping its own hitbox as small as possible.
You often see capital ships not having wings, as those use flexible turrets, while star fighter type ships use fixed gun emplacements with a high amount of manouverability.
scifi.stackexchange.com/users/63558/Dulkan
Ships in the Star Wars universe travel through a property known as "ether" which acts as a dragging force.
This explains a considerable number of issues including why ships have a top speed, how explosions can be heard in space,
why there's no overt worries about relativistic effects, why ships need to burn fuel constantly to maintain their speed, how tight turns are made and why X-Wings have actual wings Pablo Hidalgo (Head of the Lucasfilm's Star Wars Story Group) spoke to this in a recent tweet (now deleted) PH: If you need to, you could say the interstellar medium in Star Wars does have an ether, which would explain such pulpy things assound, concussion rings, visible drag, and such odd tech callouts as"an etheric rudder" from Heir to the Empire.
Only if you ⋆really⋆ needto, though.
Like if it helps you sleep at night and whatnot.
scifi.stackexchange.com/users/20774/Valorum
Watsonian Heat dispersion.
Having extended ‘foils’ (the structures you refer to as wings, at least on X-wings, are called S-foils)
provides greater heat dispersion, both by surface area, and by distancing the heat-producing cannons from the cockpit.
In Legends canon, TIE fighter radiator panels serve the same purpose.
Stabilization.
Allegedly, the s-foils provide in-atmo stabilization, and damage to them is frequently shown to cause a loss of atmospheric flight control.
This suggests they are used for in-atmo stabilization.
Based on the fact that fast-moving helicopters IRL have wing stubs partly for this purpose, it’s not too outlandish.
Greater weapon carrying capacity.
See again helicopters, like the Russian Mi-24 carry additional weapons on their wing stubs, just as X-wings do.
Fitting those cannons under the protected fuselage will require a bulkier body, which presumably is undesirable.
Doylist
They look cool.
scifi.stackexchange.com/users/41004/Daniel B
These are both out-of-universe answers, but 1.
The Rule of Cool, and 2.
SW is a fantasy with slight sci-fi tropes, so it often doesn't conform to standard space rules.
As other answers have mentioned, this applies to sound in space and also things like the bombers losing speed and falling in The Last Jedi.
Why did that happen?
Cause SW is a fantasy and George Lucas based his dogfights around WWII dogfights.
scifi.stackexchange.com/users/122182/xandroxygen
Many of the spaceships in  Star Wars , e.g. X-wings, have wings as part of their design. If there's no air resistance in space, why would wings be at all beneficial? Wouldn't it be better to have a small, compact shape to a make a star fighter easier to cram through small spaces?
Why do spaceships in Star Wars have wings?
scifi.stackexchange.com
<star-wars><spaceship>
scifi.stackexchange.com/questions/221221
scifi.stackexchange.com/users/36268/jamaicanworm
Whilst wings would not be useful in outerspace, most spaceships do eventually have to fly in a planet's atmosphere, and at this point, wings do become useful. Additionally, wings are an excellent place for placing weaponry and can also play a role in heat dissipation. The wings serve a range of purposes, for example providing stability when flying in a planet's atmosphere, placing weapons, dealing with the 'ether' of space in the SW universe and dispersing heat.
The wings are there for when the spaceships fly in a planet's atmosphere. The wings are useful for weapon placement, so that firepower can be concentrated on the front. Space in the Star Wars universe actually contains something called 'ether' which acts as a dragging force, so wings could be useful for that. Watsonian Heat dispersion - the wings help disperse heat. Also stabilisation in atmospheric conditions, like the wing stubs on fast moving helicopters and carrying weapons and because they look cool. SW is a fantasy and it does not have to confirm to natural laws, and wings fitted in with the dogfights which George Lucas based on WWII dogfights.