Politicians are supposed to be aware that generalizations are sloppy thinking and backfire.
Generalizations are used legitimately all the time.
Examples.
New York voted for Obama.
Texas voted for Romney.
Liberty is an American value.
Abortion is a Democrat value.
On and on...
And it was Donald Trump who first defined what he thought NY values were.
Cruz simply called him on it.