This is not really a cryptographical question, but rather a (rather simple) question about a finite automata.
This is a state machine; you feed in the bits of the number $n$ you're modding, starting at the msbit (and starting at the state $q0$). After processing the number, if the state you end up in is $q0$, then $n \equiv 0 \pmod 3$, if you end up in $q1$, then $n \equiv 1 \pmod 3$, and if you end up n $q2$, then $n \equiv 2 \pmod 3$.
Does it only work for determined length of plaintext?
No, it'll work for any size integer.
What algorithm is behind this scheme?
Well, I suspect it's too simple to have a formal name. The property that always holds is that, after processing an intermediate integer $\hat{n}$ (which has the binary representation of the bits you're processed so far), if $\hat{n} \bmod 3 = i$, then you'll be in state $qi$.
Here's how that property is preserved: assume that property holds at some point. Then, when you process the next bit $j$ (which means that you will have processed the intermediate integer $2\hat{n} + j$, it will transition to state $q(2i+j \bmod 3)$ (you can verify this by manually going through the state transitions). And, since $2\hat{n} + j \equiv 2i+j \pmod 3$, this preserves the above invariance. Since we start with the property holding (that's why it's important we start at state $q0$), it holds no matter how many bits you process.