A rare dinosaur skull held in Germany for decades will be returned to Brazil following concerns over its origin and ownership.