So, you should build your castle in someone else's kingdom iff that kingdom either
1. Has strong norms against castle seizure or abandonment of the king's duties in kingdom upkeep
2. Has a federation of non-king castle owners strong and unified enough to force the former point.
3. You are strong enough to provide a serious and credible threat to the king if he implements a policy that threatens you.
Example: Valve in the early 2000s before or as they were building Steam to challenge the video game publisher model. 20 years on and Valve is still printing money, while Sierra Online doesn't exist.