Can we use serial.begin command anywhere in code?
You cannot call Serial.begin() in a declaration. Like any program
instruction, you can only use it from within a function. As stated in
Juraj's answer, you can call it as many times as you want. However,
most often it only makes sense to do this in setup(), in order to
initialize the serial link once and for all at the beginning of your
program. Why would you ever want to do this initialization multiple
times?

Thinking about it, I can see two possible scenarios:


Your UART is connected, through a suitable transceiver, to an RS-485
bus. You have several slaves on this bus that require different UART
configurations (different baud rates, or number of data bits, or
parity). Then, each time you want to address one slave, you first
set your UART to the configuration suitable for that particular
slave. In this kind of situation, however, it would be more
convenient to arrange for all the slaves to share the same UART
configuration, if at all possible.
Your UART is connected to a device that continually sends data you
are not interested in. This could be, e.g., a GPS module. Since you
don't want your program to be interrupted every time a character is
received, you keep the UART disabled. Only when you do want the data
you enable it with Serial.begin(), you read as much as you need,
then you disable it again with Serial.end().


There may be other situations, but I bet they are all quite atypical
scenarios. The common practice is to call Serial.begin() once in
setup(), and have the UART enable from there on.