'I don't think they'd be any good for you.'
This part wasn't necessary. No one should be told what they should be buying unless the shopper has specifically requested personal shopper or expert knowledge assistance.
To me that would feel like gatekeeping and I would probably leave the shop feeling unwelcome.
I often spend ages looking at clothes trying to visualize them. I remember doing this in new look recently. I would not expect a shop assistant there to come over and tell me something would be no good for me.
If the shop assistant wanted to strike up a conversation go with something positive, 'that's a lovely pair of trousers' and then the customer can respond and I bet the conversation about size would then naturally flow but in a way that felt driven by the customer and therefore more welcoming.
Or the shop assistant could wait until the customer has approached the till which is an acknowledgement by the customer that they are ready to interact. I wouldn't enjoy being interrupted while visualising/thinking. I would feel rushed and would probably just put everything back and leave.
So I agree with you OP that the comment was out of place
Edited to add: a lot of PP are commenting on whether the OP was right to be offended or not, I don't believe the OP felt offended, she just asked it if was an odd comment or not. Personally I'm not focusing on the dress size part of the conversation, more the not for you part.