It is not possible to write a script in the configuration file to pull a variable for port number.
But you can write a bash function to get the port for you and place it into the correct place. For example place the following to the ~/.bashrc:
function ssh-dynamic() {
PORT=`sh get_port_for_somehost.sh`
exec ssh -p $PORT"$PORT" somehost $@"$@"
}
where the other configuration may stay in the ~/.ssh/config.