1 keep per Lord. These range from simple large stone houses that are defensible to large castles that can house hundreds and withstand an army. Poorer lords may only have thick wooden walls around their home, or may make large wooden forts instead of small stone keeps.
Along the border, especially on roads and rivers, and important harbours you might find a string of small stone or wood forts to keep enemies out, most will be fairly small and basic, acting more as a trip wire and a show of force against raiders. Depending on the financial situation of the kingdom these could be crumbling old forts that are ready to fall apart or well maintained structures that can have thriving trading towns surrounding them and soldiers in nice new shiny armour.
The number of lords and castles depends on a whole host of issues. Sometimes there will be many castles per lord, sometimes they'll be forced to have a single small keep or a palace. 1 Castle per lord, was used as a fairly reasonable means of keeping things simple, with the limited information we were given.
What is the population of the country?
The higher the population generally means more nobles to ensure no one noble gets too much power, and that they are able to maintain their lands. Bureaucracy wasn't as advanced back then, having too many people under one nobles control is simply too hard to handle. Also a king would not want a noble who rivals his power, they can't always prevent it, but eventually it reaches the point where a war occurs and either the noble is broken or the noble becomes the king.
How much power does the king have?
In countries where kings were dominate, generally castles were limited. In countries where nobles had more power, there were more castles.
Spain has 2500 castles because it had a very turbulent history. The Muslim invasion of Spain saw hundreds of keeps and castles built by both sides to defend their land. Then during the Reconquista, more castles were built. However after the Reconquista was completed, virtually no castles were built, there wasn't the need. Many castles fell into disrepair as the nobles and the royalty couldn't maintain all of them.
France before the 16th century had an extremely weak king. The nobles ruled and fought amongst each other while the kings generally stayed out of the way. They built lots of keeps and castles during those times to deal with their neighbours. After the rise of the absolute French monarch, new castles were not built by the nobles. Smaller keeps and forts were abandoned or taken over by the King, and some castles were destroyed, others were taken by the King and some were left to the nobles.
In England, after the Second English Civil War, the parliament ordered many of the castles and keeps damaged or destroyed to ensure any future civil war would be easier to put down. Again after this time new castles were not made, only palaces.
Japan in the Edo period, after Japan was united, made a law that only one castle could be built in a lords domain unless given special permission by the Emperor.
Now Bavaria was mentioned in another message, with 620 or so castles. Bavaria was frequently caught up in wars, and there was no strong central government. So the nobles, towns, cities and anyone with money really built keeps and castles to protect themselves.
So what type of government do you have?
Peaceful or Warlike?
A country at peace and having known peace for a long period of time will not have a lot of keeps and castles. Older keeps and castles will exist, but most won't be kept up.
If raiders aren't a problem, why would a mine have anything more than a basic stockade? That's money being wasted.
Nobles didn't often have a lot of money, building castles and keeps to show off is a waste that could be better spent on creature comforts, impressing allies with gifts and bribes, etc. A palace is much better for showing off than a castle.
If the border is a desert with very few people living in it, than castles aren't necessary for defence. Instead a few keeps on or near the oases will ensure no army can invade unnoticed, while saving money.
Now if war, either between nobles or outsiders is common, you're going to see lots of castles. Like in Bavaria, every place of some importance is going to have a castle, keep or fort. So is there lots of fighting or not?
Is the nation landlocked, an island, is it surrounded by equally powerful or more powerful nations right on the border, is it isolated forests, deserts or mountains, or is most of it coastline?
The major ports, rivers that are usable for shipping and major roads near the borders will have a castle or keep. The size of it, as well as the upkeep depends on how peaceful the neighbours are. Again more warlike neighbours will see well built castles, peaceful smaller nations will get keeps.
Are people spread out all over the country or are they mostly centered in a few key areas?
If this is a desert kingdom with a few cities and towns around oases, ports or rivers, you'll need very few castles. If it's more like England with multiple cities, many large towns, and a whole host of villages, castles will be spread out to cover all the various areas.
That's about it, figure out those details and you can come up with the number of castles.