If using dried beans, rinse and soak them overnight in cold water. Drain. Cover with cold water by 2 inches. Bring to a boil over medium heat, simmer 15 minutes, drain, and set aside.
In a stockpot that’s wide enough to fit the lamb shanks on their sides (or a skillet), brown the shanks well in the olive oil on all sides. Add 3 quarts cold water to the pot. Bring to a boil, uncovered, and thoroughly skim the foam from the surface. Add the salt, garlic, and one-third of the tomatoes (about 2 cups). If using dried shell beans, add them now. Adjust the heat to a simmer and cook for 45 minutes. Add the squash, onions, carrots, green beans, zucchini, the remaining 4 cups tomatoes, and the shell beans, if using fresh. Bring the pot to a boil. Lower the heat and continue to simmer until the lamb meat is very tender, the beans are soft, and the soup has developed a velvety texture, about 2 to 2-1/2 hours more. Remove the shanks and pull the meat from the bones. Cut the meat into small pieces and return them to the soup.
Meanwhile, make the pistou: With a mortar and pestle (or in a food processor), mash the garlic and salt. Add the basil and work to a paste. Work in the Parmigiano. Slowly mix in the oil to bind the sauce. Taste for salt.
When you’re ready to serve the soup, bring it to a boil and add the pasta. Cook at a light boil until the pasta is tender, about 10 minutes. The soup should be thick, but if it's too thick, add hot water. Taste for salt and serve with a dollop of pistou stirred into each bowl.