When something is done legally, it follows the rules of law. If a couple has gotten a marriage license and a ceremony's been performed by a judge, they are legally married.
When you act legally, you obey the law. If you're driving a car, legally turning right at a red light generally involves using your turn signal and stopping to make sure the road is clear. When an American turns twenty-one, she's legally considered to be an adult — in other words, the law says that's the age of adulthood. The Latin root of legally is legalis, "pertaining to the law," from lex, or "law."