A Mexican-British man arrested in Qatar for being gay has been sentenced to prison but can leave the country after paying a fine.