Well it may void the warranty, and I think does so with most manufacturers, but I don't think it's actually illegal. Check Samsung's terms and conditions.
I think I can safely say that the best thing to do if you don't understand rooting is to leave the phone well alone.