Preheat the oven to 375°F.
In a large skillet, heat olive oil over medium heat. Add the chopped onions, celery, and carrots. Sauté for about 5 minutes until softened.
Add the chopped mushrooms and garlic to the skillet. Cook for another 5-7 minutes until the mushrooms release their moisture and begin to brown.
Stir in the cooked lentils, walnuts, thyme, rosemary, salt, pepper, soy sauce, and balsamic vinegar. Cook for an additional 2-3 minutes, mixing well. Remove from heat and let cool slightly.
Roll out the pie crust and fit it into a 9-inch tart pan. If using, sprinkle the grated Parmesan cheese evenly over the bottom of the crust.
Pour the lentil mixture into the crust, spreading it evenly. If desired, beat the egg and brush it over the crust for a golden finish.
Bake in the preheated oven for 30-35 minutes, or until the crust is golden brown. Allow to cool for 10 minutes before slicing.