It sounds like you are using sklearn, in which case I can confirm that a pipeline will be able to accomplish what you describe. Cross Validated isn't the right forum specifically for programming related questions, so forgive me if I don't walk you through an exact solution. However, this is a statistical analysis forum, so you'll allow me to share some thoughts on your proposed methodology.
I think you must acknowledge the assumptions you're making and determine whether they would hold in a real application. What you assume is that when predicting the response of a given individual, you will have information on the responses of his family. In the case of the titanic, the deaths of all individuals are broadly contemporaneous. So it seems unlikely you would have information on the status of an individual's family but not on the individual. If you create a model on training data where you do have this unusual information, you will find that you cannot apply the model to future data where you don't have this information. In the case of the titanic disaster, it might be silly to think of predicting a larger "population" since we already have data on everyone on the ship, and there is no larger population. But, if this is typical of Kaggle competitions, it is not typical of real applications. Consider, for example, you want to use your model to predict the relative risk of death of individuals on another similar ship in the case of a disaster. Your model clearly would not be applicable since it would not have, in advance, any information on the outcomes of a person's family.
Because many people use Kaggle competitions to practice modeling skills, it is crucial to question the methodologies and avoid exaggerating performance through data leakage, dredging, and overfitting.