I'm guessing it's legal because they warn you before denying it (ie. they allow you to return it this time, but warn you that you won't be able to return next time)
On the bottom of every Home Depot receipt is "THE HOME DEPOT RESERVES THE RIGHT TO LIMIT / DENY RETURNS. PLEASE SEE THE RETURN POLICY SIGN IN STORES FOR DETAILS."