Heat the oil in a medium-sized frying pan. Sauté the chopped onion in the oil with the thyme, coriander, and pepper until the onions are clear and soft, about 10 minutes. Stir in the chopped walnuts and shredded tofu. When heated through, stir in lemon juice and soy sauce. Remove from heat.
To make the layer of mashed potatoes, place the cubed potatoes in a saucepan and cover with lightly salted water. Bring to a boil, then simmer until potatoes are soft (about 8 minutes). Drain, saving the hot potato water to use in the mushroom gravy.
Place the potatoes in a large bowl and mash. Add the margerine or butter, milk, and salt. Stir well.
For the gravy, heat the vegetable oil in a skillet. Stir in the mushrooms, soy sauce, and pepper. Sauté, stirring occasionally, until the mushrooms are tender. Add hot potato water and bring to a boil. Slowly stir in the cornstarch mixture and cook at a low boil, continuing to stir, until the gravy is clear and thick.
Preheat the oven to 400°F.
Oil a 9-inch-square casserole dish. Spread the tofu mixture across the bottom of the dish, followed by the mushroom gravy and the mashed potatoes. Dot the top with butter or margarine. Bake at 400°F for 15 to 20 minutes until the top becomes golden.