First, you don't know that, had you not gone after the barbarian outpost, it would have sent two spawns at you. [Actually, two spawns implies two barbarian outposts, but that's besides the point.] You already noted 2 of the city-state Nalanda's warriors were killed. [So it's possible that one outpost scouted you, a different outpost scouted them, again besides the point.] My point is, you could have let Nalanda deal with the barbarians, at least some of them. It has city walls. The AI likes to kill units, likes to pillage tiles and trade routes. If you have none of those, and someone else does, it will go after that someone else.
However, let's assume a worse situation, where it's just you versus a dozen barbarians of the horse variety. What I do is defend. I use the barbarians to get the boost for Archery and the boost for Bronze Working. I build scouts (how many varies), and use them to tempt and tantalize the barbarians into poor positions, so they get killed, especially by the slinger inside the city. Meanwhile, the scouts get promoted as well.
Assume 3 tiles have not yet been improved with a builder, for the boost for Craftmanship. After building a slinger and enough scouts, I build a Monument, and go for Craftmanship without the boost. When the Monument finishes, and I'm waiting for Craftmanship, I'll build a builder if I don't have one, after which I store up production towards a settler. (And maybe more scouts, if the ones I have already have the 1st promotion.) The builder can also be used as bait, although one has to be more careful versus horse units. (Note that barbarian horse archers and horsemen have less movement than non-barbarians. So appropriately-promoted scouts can run away.)
Before the settler finishes, I'll have Craftmanship. Then I run Agoge, building warriors until I know Archery, after which I'll build a couple archers, so eventually I can get the boost for Machinery. After learning Craftmanship, I usually go for Foreign Trade, boosted or not. Again, the Monument makes up the difference for not getting the boost.
With the next change in Civics, I switch from Agoge to Discipline. With 2 archers and 2+ warriors, I have plenty to handle even two barbarian outposts, and I'll have the scouts ready to find them (or otherwise explore). I won't upgrade the original slinger, partly because I usually give it the garrison promotion (less useful in the field), but mainly because I use it as bait. The spearman in an outpost will come out when it sees the slinger, even if it cannot attack it immediately. Besides, with Discipline, a slinger can take one hit from it. I arrange to take the outpost immediately with another unit. I also switch from Urban Planning to Ilkum, and produce builders (after finishing the settler). I send the builder I have with the settler, maybe after improving 1-2 tiles that increase production (and of course after repairing), and improve other tiles near my capitol with the next builder. Also, I should have finished Bronze Working by then, or shortly, so I'll know where the Iron is (or isn't) when deciding where to settle. An extra benefit of the Monument is more cultural border expansion, so the 2nd builder will have more choices to improve. If my either my capitol or my next city is coastal, I may also use a builder with 1 charge remaining to scout the coastline.
After Foreign Trade, I go for Military Tradition, stop 1 turn way from finishing after boosted, then go for Early Empire, stop 1 turn away from finishing after boosted, then go for State Workforce. Before I get 1 turn away from finishing that after boosted, I should have taken out a barbarian outpost, so I'll finish Military Tradition, switch back to Urban Planning, and start producing my 1st district, maybe an Encampment, since I know Bronze Working.
If there's more than one barbarian outpost, I don't have to take out the others. One consideration is if I know whether or not I need the Era score for a Golden Age. When clearing an outpost this early, a turn later another spawns, and sometimes I prefer to leave the one I know about, and control its scouting, than endure a new one. Plus, if it's spawned horse units, there are horses near it. The AI doesn't like to settle near a barbarian outpost, while if I settle near it, then clearing the outpost gives an extra +1 to the Era score.
Finally, as
@IsabelBraganca said, I don't think barbarians can take a capitol. I think I've seen it not take mine even at zero health, and I think I've seen it not take that of an AI even at zero health. I think the reason is that barbarians raze cities, and they cannot raze capitols. In which case, maybe then slinger then monument then scouts.
P.S. I forgot to add, once I know Bronze Working, particularly in this situation, I like to build one spearman, while running Agoge. Not only does it get combat bonus against these horse units, but I can get the boost for killing a unit with a spearman.