Heat the oven to 220 C / 425 F. On a 33 x 46 cm / 13 x 18 inch rimmed sheet pan, toss the tomatoes, onion, carrots and unpeeled garlic with 2 tbsp olive oil and 1/2 tsp salt. Arrange the tomatoes cut side up in a single layer and roast for 35 minutes, until the edges are blackened in spots and the juices look syrupy.
While the vegetables roast, combine the lentils, water or stock, tomato paste, oregano, bay leaf and 1/2 tsp salt in a 5-quart / 4.7 L Dutch oven. Bring to a boil, reduce to a gentle simmer, and cook for 25 minutes, until the lentils are tender but still hold their shape. Take the pot off the heat, cover it, and leave it until the tomatoes finish roasting.
Squeeze the roasted garlic out of its skins into the Dutch oven, then scrape in the tomatoes, onion, carrots and all the pan juices. Remove the bay leaf. Pulse with an immersion blender five or six times, or mash with a potato masher, until the sauce is chunky with whole lentils still visible. Stir in the balsamic vinegar, red pepper flakes and black pepper, then simmer uncovered over medium-low heat for 10 minutes, stirring often, until the sauce mounds on a spoon. Season with the remaining salt to taste.
While the sauce simmers, boil the spaghetti or rigatoni in a 6-quart / 5.7 L pot of water with 1 tbsp salt until al dente, usually 10 to 12 minutes. Scoop out 120 ml of pasta water, then drain. Toss the pasta with the sauce in the Dutch oven over low heat for 1 minute, loosening with pasta water as needed. Drizzle with the remaining 1 tbsp olive oil and scatter the torn basil on top.