Thank you for choosing Just Answer. I am afraid the IRS can attach (levy) your social security. However, they would have sent an intent to Levy letter prior to the levy being put in place. I have attached a link to the IRS. I would suggest that you contact the National Taxpayer advocate help line. You may be able to speak with someone who is a little more sympathetic to you individual situation. If that does not work, I then suggest hiring a good CPA to intervene for you with a power of Attorney.
My apologies for beating around the bush with the answer. Yes it is legal for the government to collect back taxes from someone who has dementia or any other ailment. There are ways to get the tax reduced with good legal representation in an offer and compromise case.