Preheat oven to 400°F (200°C) and grease an 8x8-inch baking dish.
Layer sliced potatoes and onions evenly in the dish.
Make roux by melting butter, whisking in flour and salt, and cooking for 1 minute.
Whisk in milk and cook until thickened, about 3 to 5 minutes.
Stir in cheese until melted and smooth, then season with pepper.
Pour sauce over potatoes, cover with foil, and bake 75 to 85 minutes until tender.
Uncover and bake 10 minutes more or broil briefly to brown the top, then rest 10 to 15 minutes before serving.