Yes, acting like a police officer online can be illegal:
Impersonating a police officer
In the United States, impersonating a police officer can result in a fine or up to three years in prison.
Felony charges
Impersonating someone online can be charged as a felony, which can result in up to three years in prison and up to $10,000 in fines