Obviously the UA agent somehow thought connecting in Canada when your start and end destination are both in the USA was illegal. I've never done this myself, but I can't imagine it being illegal, and I'm surprised that a UA agent would tell you it is.
Did you actually have to pass through US or Canadian immigration? Did you need proof-of-citizenship to fly this route?