When you detach a public IP address from an Azure Application Gateway, you can indeed create a new public IP address with a new DNS name and associate it with the Application Gateway afterward. However, it's important to note that the Application Gateway does not support changing the public IP address after creation. Therefore, you will need to create a new public IP resource and associate it with the Application Gateway after detaching the existing one.
Additionally, if you are using a dynamic Basic IP, it will only change when the gateway is stopped or started, but the DNS name associated with the Application Gateway frontend does not change over its lifecycle. Thus, using a CNAME record for a friendly DNS name is recommended if you need to maintain a consistent DNS name for your application gateway.
Make sure to plan the migration carefully to avoid any downtime or service disruption during the transition.