Start cooking the onions and garlic: Set a heavy, medium-sized cast-iron pan or skillet to medium heat and add oil. Once hot, add the onions and garlic. Cook, stirring occasionally, for 8 to 10 minutes, until the onions are soft and translucent. During this initial cooking, very mild, golden-brown edges are okay, but if you notice anything deeper in color, lower the heat. You can also add a splash of water to the pan to immediately reduce the heat if needed. Season with salt and pepper, and stir in the sugar.
Caramelize the onions: Lower the heat to medium-low, and cook the onions and garlic for 30 minutes. Stir occasionally, and adjust the heat as needed to prevent any burning. At the end of the 30 minutes, onions should be deep-golden brown in color (but not burnt) and taste quite sweet. If you have the time, you can also continue caramelizing the onions for an additional 30 minutes to bring out even more sweetness and complexity. Season with salt and pepper.
Cool the mixture: Remove the mixture from the heat and transfer to your serving bowl. Let cool until mixture feels just slightly lukewarm, about 5 minutes.
Prep the scallions and lemon: While the mixture cools, thinly slice the scallions. Juice the lemon (you should have about 1 tablespoon of juice).
Mix the base: Stir in the sour cream, lemon juice, and most of the sliced scallions (save about a tablespoon for garnish) into the onion mixture. Season with salt and pepper.
Chill the base: Place the serving bowl, covered, into the refrigerator for 30 minutes (and up to 1 day) to allow the flavors to develop. When ready to serve, take the dip out of the fridge and taste a spoonful. At this point, you can season again with salt and pepper. If the dip tastes slightly too "sweet", you probably need to add a little bit more salt or lemon juice, depending on your preference. I find those little adjustments make a huge difference in the flavor.