Authorship questions inevitably end up having two threads: what should be and what happens. The "what should be" is that the amount of intellectual work (as described in the Vancouver Protocol)
1. Conception and design, or analysis and interpretation of data
AND
2. Drafting the article or revising it critically for important intellectual content
AND
3. Final approval of the version to be published.
that each author has put into the work. As with most agreements, it is best to discuss this in advance and agree on how to evaluate the work done. Usually the first author is in charge of writing and the other author(s) provide feedback and contribute to the writing. If everyone follows these rules then the argument is fairly "straightforward".
In reality, we have to also deal with different types of personalities and other situations that affect judgement. It is not uncommon for persons to want first authorship if they are up for promotion or if they see that something they did not fully think was great actually is. The list could be made long. Straightening these cases out is sometimes (if not often) really tough.
Being pragmatic, I often think about if the situation will hurt me and evaluate if the fight is worth it. In the case of a PhD student, having ones advisor as first author is not necessarily a bad thing since, hopefully, the advisor is well-known and respected. Hence some of that rubs off on the co-author. As a PhD student I think a valid argument is that you need first authorship on some of the work in your thesis. This is a particularly good argument if the "switch" occurs repeatedly.
Arguing against irratianal excuses for first authorships will be hard or near impossible to win so I am a little pessimistic when it comes to such cases. You need to evaluate the situation yourself, gather objective arguments for your claim and possibly asking other faculty for advice and support.