Why is there sugar in a seven-layer salad?
The recipes that I have seen didn't have much sugar and it is universally in the dressing. The dressings are mayonnaise based and a small amount of sugar gives them another facet to their flavor. This dressing reminds me of a simple coleslaw dressing which will include the mayo and sugar as well as buttermilk and lemon.

Because the sugar is in the dressing it will apply to all the layers equally so there is no particular layer that should be sweetened more than the others.

Keep in mind that this salad is southern cuisine which tends to value flavor over nutrition. Sometimes to a fault, of course.

The sugar serves no mechanical purpose. It will eventually pull some the liquid out of the vegetables but, as there is so little and the dressing is not mixed in, the effect would be negligible.

If you prefer the salad to be less sweet and are not worried about authenticity feel free to leave the sugar out. Alternatively if you would like to throw authenticity to the wind altogether you could leave in the sugar and add buttermilk and lemon juice to the dressing and give the salad more of a coleslaw-like zing.