Step 1: Preheat your oven to 375°F (190°C).
Step 2: Peel and slice the Yukon Gold potatoes into 1/4-inch thick rounds.
Step 3: In a large skillet, melt the butter over medium heat. Add the sliced shallots and cook until translucent, about 3-4 minutes. Stir in the minced garlic and red pepper flakes, cooking for an additional minute until fragrant.
Step 4: In a large bowl, combine the heavy cream, mayonnaise, and 2 cups of the shredded sharp cheddar cheese. Stir until well mixed. Add the sautéed shallots and garlic mixture, along with the drained pimentos. Season with salt and freshly ground black pepper to taste.
Step 5: In a large baking dish, arrange a layer of potato slices. Pour a portion of the cheese sauce over the potatoes, ensuring even coverage. Repeat the layering process until all potatoes and cheese sauce are used, finishing with a layer of cheese sauce on top.
Step 6: Cover the baking dish with aluminum foil and bake for 45 minutes. Remove the foil and sprinkle the remaining 1/2 cup of cheddar cheese on top. Return to the oven and bake for an additional 15-20 minutes, or until the top is bubbly and golden brown.
Step 7: Once out of the oven, let your Pimento Cheese Potato Gratin sit for about 10 minutes before serving.