Tl;dr At most 70 years, but probably less.
rand al'thor has done an irrefutably good job determining a lower bound for the time The Doctor was in the castle, so I will attempt to logically determine an upper bound.
In the iteration we initially see The Doctor in, he had been in the castle for 7000 years, based on the alignment of the stars. In the following iteration, he again says that the stars are aligned such that 7000 years have passed.
This then ensures that each iteration is less than 1000 years, as he would have observed that he was 8000 years in the future had that amount of time passed. This is the most certain answer that I can give.
However, we can then at least assume that it is also less than 500 years, as it is unlikely he would round up or down twice to the same number if they were 500 years apart (possible, but unlikely).
The only other evidence we have to see how long each iteration is, is by calculating how many iterations have passed. To calculate this, we can use the number skulls that he sees at the earliest point that they are seen underwater. It is unclear how many there are that we see after 7000 years have passed, but I would hazard a guess with at the very least 100 skulls.
There isn't really any way to calculate how long it took him to make the same revelations in the first iteration in order to leave clues for later versions of himself, but it will have taken him at the very least the same amount of time as the rest, so without further evidence we will just assume that it did.
This means that it took, at the very most, 70 years per iteration. This is possible, as with the age of The Doctor I'm sure that amount of time could pass and he wouldn't even bat an eyelid.
If there is a more accurate answer for how many skulls there were when he fell in the water the first time that we see him in the castle, that upper bound could come lower. It is likely that there more than 100, but for an absolute upper bound I chose the absolute minimum number that there could reasonably be.