It's not sold as a single ticket connecting flight (which would be "cabotage" and against the rules) presumably. Either way, they don't expect US-US connections in Canadian airports, so you'll have to do Canadian immigration then turn around and do US immigration.