It's a nuanced topic, but generally speaking, custom firmware on a PSP is not inherently illegal. However, its legality depends heavily on how it is used and your jurisdiction.
Sony has a history of legal action against sites hosting custom firmware, arguing it facilitates illegal activity.
Custom firmware is not automatically illegal, but using it for piracy, distributing it, or circumventing copy protection is. Understand the legal risks in your region and use the device responsibly. This information is for general understanding; consult a legal professional for specific advice.