Hello @braveyav and welcome to the ST community,
As you stated, each GPIO pin contains many alternate functions. To enable that function, you need to configure it by software. You can either modify that function at run time in your application but you need to ensure there will be no conflict externally by hardware.
What is functionality of PAx pins ?
-> look at the datasheet for each pin. For example: PA2 has three functions: UART2_Tx or ADC input or TIM2_ CH3

If you enable USART2 for example by software and select PA2 for Tx, PA2 will be reserved for this function. But as I stated before you can change that function in your application bu selecting TIM2 at runtime but you need to do that in a correct way.
Use CubeMx tool to configure the peripherals with their corresponding IOs. You can donwnload the tool from this link.
So you configure the peripherals with CubeMx and you generate the code with that configuration. Than you can use CubeDE tool (downloadable fom this link) and add the user code and compile/debug.
Read also this tutorial: STM32CubeIDE 2.0.0 workflow tutorial
Hope I've answred your question.
To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.