Is it illegal to turn health code P into yellow?

Break the law.

If a person who uses a forged health code carries COVID-19 himself, his behavior may constitute a crime of endangering public safety in a dangerous way. According to the relevant provisions of the Interpretation of the Supreme People's Court and the Supreme People's Procuratorate on Several Issues Concerning the Specific Application of Laws in Handling Criminal Cases that Hinder the Prevention and Control of Infectious Diseases, those who intentionally spread pathogens of infectious diseases and endanger public safety will endanger public safety in a dangerous way in accordance with the Criminal Law of People's Republic of China (PRC).

Those who have not caused serious consequences shall be sentenced to fixed-term imprisonment of not less than three years but not more than 10 years, and those who cause serious injuries, death or heavy losses to public or private property shall be sentenced to fixed-term imprisonment of not less than 10 years or life imprisonment or death.

If you simply forge the health code, it is a crime of maliciously spreading rumors and deliberately disturbing public order.