STM32F407VG Pin Assignment
Work order in a professional project:


Determine what the product should do and write a spec.
Find out which external hardware that is needed. In particular, which serial buses do you need, how many ADC channels, how many PWM channels, how many GPIO etc. This should preferably be in the spec too.
Pick a MCU based on what you need. Not based on finding one on some hobbyist board or in a packet of corn flakes.


So the obvious answer to the question is then: pick GPIO from pins that aren't used by other hardware peripherals needed in your project. Port routing alternatives may be available.

Once that is sorted out, you should place pins related to the same external hardware the same GPIO port. For example if you need to scan 8 buttons, it will be wise to place all 8 in adjacent order on "port x". 

And finally, if none of the above matters, pick pins that gives shortest paths/best layout on the PCB.