NOTE This quest is available if you've been banished from The Institute for any reason. This can happen by declining Father's initial offer, opting out after The Battle of Bunker Hill, or attacking a scientist amongst others.
Speak to Preston Garvery about your experiences. He will opine on the situation based on the present state of the Minutemen and whether they can take on the Institute. He will either say you must recruit and build up more Settlements or if you have at least 8 settlements, he will warn you about an imminent Institute attack on The Castle.
Once the attack is imminent, the quest Defend the Castle will become available.