Also, I have another case where in a managed solution when i add run only users, a unmanaged layer is being created automatically to the managed solution.
Kindly help to solve

Here are some steps and checks that can help resolve the issue:
Check Permissions: Ensure that the user you're adding has appropriate permissions. They should have at least the Environment Maker or System Administrator role. If you're adding the user to a specific flow, ensure they also have the right permissions in the flow's environment.
Check Licensing:Confirm that the user has a proper Power Automate license (e.g., Power Automate per user or per flow). Without proper licensing, users might not be able to be added as "Run-Only Users."
Managed Solution & Unmanaged Layer: The creation of an unmanaged layer when adding run-only users in a managed solution is a known behavior. To avoid this, consider checking the version of the solution. If possible, work in a solution context where the unmanaged layer won't interfere.
Review the API Request: If you’re using an API to add users programmatically, ensure the request body and headers are properly formatted. A 400 error often indicates an issue with the request. Double-check the API documentation to ensure the request is structured correctly.
Lock Solutions for Deployment: If you're working with a managed solution, avoid making changes directly to the solution while adding Run-Only Users. This could trigger the creation of the unmanaged layer. Instead, make sure the solution is locked for deployment and only add users manually via the Power Automate interface if necessary.