A Greek court ruled that migrants arriving on Aegean islands near Turkey should be allowed to travel freely around the country, officials said, a decision that could alleviate dire conditions on the islands, but might derail a pact aimed at limiting arrivals.