Without a precedent, there is no answer about legality. The French law about military uniforms (and by extension postal workers if they are government employees) is based on the Geneva Convention based on precedents and war crimes.
Disguised as a postal worker, René Veuve acquired and transmitted information about crucial enemy infrastructure, such as Le Bourget airport, an oil refinery and an underground rocket factory.
In this case René was a hero, now imagine the opposite happening from the Axis powers.
For this question, no one on the internet can/should say whether it's legal or not for a civilian to wear a generic* pilot's uniform and board a flight.
The precedents we have show that those who did it, did it for illegal reasons, not for fashion.
* For the non-generic uniforms as in this case, a man was charged in the U.S. with falsely impersonating persons privately employed. But I'd say from a distance you can't tell the difference, and so a prosecutor may ask for the same charge (only one way to know).
Security
The airport security may stop the good-looking person for questioning and they will be searched. Because that's one way to try to get contraband in/out of a country.
If flying internationally, the border control officer may have a question or two to the non-pilot in uniform.
For the U.S., pilots in uniform are required to show two IDs:
(...) one from their company and one from the government, to be checked against a secure flight crew database.
It may be seen as a way to skip the security lines.
Airline / flight crew
The airline personnel may object and deny boarding because it may be taken as an impersonator with a malicious intent to gain access to the cockpit.
Passengers don't know better, and the airline may not like it for their passengers to think their pilot is sleeping (see story below), or worse, drunk (or will they deny drinks?).
Man was wearing a Cathay Pacific uniform and claimed he was off-duty. Flight attendants grew suspicious and soon learned he was not a pilot.
Note: Not all airlines allow their staff to wear uniform when off-duty.
In other news, a drunk pilot in uniform may cause panic and stress to passengers, what if that civilian is also intoxicated?
Common sense says to avoid that.
I don't think we will find an aviation regulation for that, it will be a local matter fit for Law.SE, i.e., if you were denied boarding, do you have the legal grounds to sue the airport/airline?
Once someone tries it, sues the airline/airport, and the court passes a sentence, then we'll know (for one jurisdiction at least).