I am trying to install virtual box but its showing me error as The installer has detected an unsupported architecture. VirtualBox only runs on the amd64 architecture. I am trying to download it on Mac M2 chip

For whatever reason – perhaps Oracle is having a fight with Apple, who knows – it just isn’t supported. People use a variety of alternatives to it. We use mulitpass a lot for tasks at KodeKloud. VMWare for some things.

What are you trying to do, and for hosting what OS?

I am going through a course DevOps Pre-Requisite there is a module how to do lab set up, I am trying to install it on my Mac

VirtualBox does not work on Mac M1 - so you can’t install or use it on Mac M1. What OS did you want to install on a VM in VirtualBox?

I am trying to install CentOS

You can use UTM | Virtual machines for Mac (getutm.app) and either install a native ARM64 distro or use a regular CentOS x86_64 ISO and have it emulate.

I’d personally go for one of the ARM64 ISOs here:
Fedora Server | The Fedora Project
Fedora is upstream to CentOS and should operate the same way.