Foreign tourists will be banned from entering cannabis cafes in Amsterdam after a ruling by a Dutch judge.