Does Germany require a Habilitation or W1 before hiring someone for a W2 position if they are coming from outside of Germany?
Not generally, and often not even for people from "within" Germany. The strict Habilitation requirement is in the decline, also and and particularly in the best universities in Germany.
What is required though is a "habilitation-like" career stage / qualification. That is, there should not be any doubt that you would be able to receive habilitation easily if you applied for it with your current CV. This is generally no problem for candidates that already hold a position comparable to a W2 professorship (say, an associate professor in the US or a Senior Lecturer in the UK), but if you are currently a postdoc it is important that you underline your independence in research and teaching, your standing in your community, as well as your ability to acquire grants and external funding (i.e., the criteria among which habilitation is usually decided).
Another factor may be academic age - in many cases academically older candidates will find it easier to communicate that they are in a career stage comparable to W2 professor than excellent younger ones. I have the impression that in Germany many commissions either do not, or fail to, properly normalize qualifications based on academic age; that is, they will often prefer more modestly qualified senior candidates over very promising younger ones.
Finally, another challenge may be language. You may still find a requirement to be able to teach in German in many job postings for positions in Germany.
If so, is this rare? What's the standard trajectory in German academe for someone that has done postdocs elsewhere?
I think the German trajectory for most people from within and the outside is like that:
PhD student -> postdoc (sometimes for many, many years) -> [optionally] W1 / junior professorship -> either W2 or "bad" W3 professorship, depending on experience -> W3
In most cases, none of the steps after PhD student -> postdoc happens automatically or based on a tenure clock. The usual way to e.g., get one's W2 position upgraded to W3 is by getting a competitive offer for a W3 position at another university. Also note that traditionally many academics in Germany never held a W1 position, but rather did extensive postdocs and/or one or more "Vetretungsprofessuren" (akin to a visiting professor).
is this rare?
(I am assuming the question is whether it is rare that a postdoc from the outside gets hired at a W2 position)
It's not rare, but it is also not insanely common. While full professors do commonly get hired from the outside (especially at the top institutions), my impression is that most are already in a professor-like position before making the move. This naturally also means that most outside hires seem to be on W3 rather than W2 level. As always, when one is trying to break in from the outside, you are in a slightly disadvantageous position in comparison to somebody who is already "in the system".