Creating a State Diagram and State Table with known output
The key idea is that input 10101 needs to output 1 twice, since 101 appears twice in the input sequence. Your state machine won't notice the second 101 sequence.

In the solution, S1 indicates you have a 1, S2 indicates you have 10, S3 indicates you have 101, and S0 indicates you have 0 without a 1 before it. (To answer your question, S3 goes back to S2 when you get a 0, because you now have 10 and are waiting for a 1.)

The solution diagram looks like the arrows from S2 to S3 are wrong; you should move from S2 to S3 when you get a 1 and S2 to S0 when you get a 0.