You will recall that Agent Smith has become essentially a virus now, taking over various other beings in The Matrix. The dialogue you have quotes above is due to his 'consumption' if you will of The Oracle.
You raise several questions so I'll address them one-by-one:
What happened here?
Smith comes to the realisation that his consumption of The Oracle is having an impact upon him.
Why is Smith talking to himself like that, and why is he surprised by
what he said?
He is surprised by what he has said because he didn't willingly say it; it just came to him. Here he probably realises that his consumption of The Oracle is having an impact upon him. It wasn't Smith talking here, but The Oracle and he was confused as to why one of the people he has consumed is speaking from within him.
As pointed out in jono's comment, note that Smith refers to Neo as 'Neo', his real name, rather than 'Mr Anderson' as he usually does. Smith isn't talking; it's The Oracle talking through Smith.
Finally, why does he suddenly become afraid of Neo?
As pointed out in Hypnosifl's comment, even The Oracle couldn't see the future 'beyond a choice they cannot understand'; this was one such choice and Smith suddenly became afraid because he couldn't see what was going to happen.