Yoga pants are sweat pants minus the stretchy bands at the ankles and sometimes waist.
Leggings are basically footless tights. Tights are meant to be legs coverings worn under skirts, short dresses, leotards, or long shirts. Any situation where stockings or pantyhose cannot be worn.
Until recently the fashion police would arrest you for wearing leggings or tights with the following exceptions. It is for your job (athlete or dancer), you were a child, or dressing up for a 80's theme party.
They are cheap to make and manufacturers are more than happy to delude women into thinking they are fashionable. Even though <5% of women have the bodies to wear anything that skin tight and not be mercilessly mocked.