You did nothing wrong. And you were not "treated as a criminal".
Airport security, like most forms of security, is not black and white. There is no magic button the security agents can press to know if you are 'good' or 'bad'. Instead, they rely on a number of indicators to determine if a person is likely to be a threat or not.
In your case, you are already given a 'generally good' score as a starting point. Anyone over 75 years old (or under 12) in a US airport is automatically treated as a lower risk than the average person, and as a result is given "TSA Pre" where the checks carried out are generally fewer and less intrusive - including as you stated the ability to leave your shoes on.
This does not mean that nobody over the age of 75 years old is a threat to security, so there are numerous triggers that can cause the TSA agents to carry out further screening on a passenger. This isn't just the case for passengers over 75, but for ALL passengers passing through the airport.
These triggers are varied. Some of them are random (eg, the metal detector machine will randomly select one-out-of-every-X passengers for additional screening). Some of them will be behavioral - such if the TSA staff see you looking or acting suspicious.
And some of these triggers will be based on the items you are carrying through the checkpoint.
Coffee - especially ground coffee - is an item that is of interest from a security perspective. Ground coffee can be used by criminals for transportation of drugs (eg, here and here) - partially because they look similar on an X-ray, and partially because the smell of the coffee can mask the smell of the drugs from sniffer-dogs.
Once one of these triggers has occurred, TSA still will carry out additional screening on the passenger and/or their bags. This could involve anything from a simple hand-swab for explosives, right up to a full strip-search of the person and checking the entire contents of their carry-on (and even checked) bags.
In your case, it sounds like that involved a frisk search of your body, and a further investigation of the coffee tin. Once the officers had concluded that you and your luggage were not a threat, they let you continue on to your flight.
As a part of this, the TSA officers should have given you the option to have the frisk carried out in private, which would have avoided your "husband, children and grandchildren watching", but I can only presume you said no to this.
You don't have to like that this occurred, but you were not in any way treated like a criminal. At any time you could have opted out of the security, however this would have resulted in you not being given access to the terminal and not flying that day.
(As someone that flies almost every week I've been through this numerous times. Never due to coffee, but numerous other triggers ranging from a bottle of water in my bag, to triggering the metal detector, to simply being randomly selected)