Hi there AlexNow,
It sounds like you were prompted to change the passcode on your iPhone, and you're unable to do so because an error alert appears indicating it cannot be set. We're glad you're here, and we can help.
To start, it sounds like you may have a managed device or there is a configuration profile installed on your iPhone. Have a look at the 'If an alert says to change your passcode or you can't adjust your passcode settings' section of this support article to learn more:
Use a passcode with your iPhone, iPad, or iPod touch
"Configuration profiles and email accounts based on Microsoft Exchange (common with business or education devices) sometimes have passcode policies that cause issues like this:
- You can't turn off your passcode.
- You can't change passcode settings because they're unavailable, gray, or dimmed.
- You see an alert about a Passcode Requirement. For example, you might see a message that says you must change your iPhone unlock passcode within 60 minutes."
Take care.