Maharil (d. 1427) gives over this explanation, so we should look for sources from about that time. I did find a source from a bit later which connects almonds to raising up phlegm:
From this website:
This business of almonds stopping excessive secretions is not exclusively an Indian idea. If we travel to England in 1597 we find Gerard running his mouth about almonds acting to stop the over production of mucous.
"white juice, like milke, which over and besides that it nourisheth, and is good for those that are troubled with the laske and bloudie flix (bloody discharges), it is profitable for those that have the pleurisie and spit up filthie matter;for there is likewise in the almonds an opening and concocting qualitie, with a certain clensing facultie, by which medicine to the chest and lungs, or lights, and serve for the raising up of phlegm and rotten humors. It also cures old coughs."
The almond is a member of the Rose family and the entire family contains tannins, chemicals found in plants that were once used in tanning leathers. Tannins dry out animal skin and convert them into leather. They do the same thing to the linings of the human body. Almonds contain tannins in the brown peal that surrounds the seed and it is likely that these chemicals are in part responsible for the drying nature of the almond.
I'm not certain it means stopping phlegm, for this 1597 source mentions "raising up of phlegm."
From another website, about white walnuts:
Has been used to clear long standing phlegm or mucous.
From what I can make out, it may be the result of tannin in these nuts. But again, I do not know what modern medical science has to say about nuts and mucus.