Many karate-ka make the mistake that the wearing of hakama Japanese attire has its origins in aikido or other particular martial arts styles. Hakama are typically used for non-martial art & martial art formal occasions in Japan and were originally part of society class/rank distinction (hence the Samurai wore them for this reason as well as some functional attributes of horse riding).
Still today the hakama is used in Japanese society at formal occasions and such events as tea ceremonies, weddings, and funerals. Hakama are also regularly worn by practitioners of a variety of martial arts, and also in karate by some of the styles founders at fomral gatherings. Below you can see Shotokan's founder (Funakoshi sensei), Mabuni Kenwa sensei (Shito-ryu founder), Tani sensei (Shukokai founder) and Dr Greg Story sensei (a key shito-ryu senior in Australia in the 1980s who has lived most of his life in Japan).
Funakoshi sensei Mabuni Sensei with peers Tani sensei Greg Story sensei mid-80s Jason Armstrong (LHS) & Greg Story
Other examples include Sumo wrestlers, who do not wear hakama in the context of their sport, but are required to wear the traditional Japanese dress whenever they appear in public. In addition to martial artists, hakama are also part of the everyday wear of Shinto kannushi, priests who maintain and perform services at shrines.
In regards to the samurai wearing them for class distinction, the baggy flowing material served to protect their legs while riding, but it is also generally accepted that they had the side benefit of disguising their stance and footwork from their opponents. For some, the 7 folds in the hakama (5 in the front, 2 in the back) are said to represent Confucian virtues valued by the samurai:
Samurai visiting the shōgun and other high-ranking daimyo at court, were sometimes required to wear very long hakama called naga-bakama (long hakama). These resemble normal hakama in every way except their remarkable length in both the back and front, forming a train one or two feet long and impeding the ability to walk normally, thus helping to prevent a surprise attack or assassination attempt.
Outside of certain martial arts, women wear hakama less often. But examples include, graduation ceremonies and for traditional Japanese sports such as kyudo (archery), some branches of aikido and kendo, and the image of women in kimono and hakama are culturally associated with school teachers. Just as university professors in Western countries don their academic caps and gowns when their students graduate, many female school teachers in Japan attend annual graduation ceremonies in traditional kimono with hakama.