Feature selection when feature X1 and X2 are highly correlated conditionally I have a query based on correlation among features. 
Case 1 :  Let feature X1 have two categories. For all X1=0, there is a high correlation between two variables X2 and X3. But no or very low correlation between X2 and X3 for another category of X1(at X1=1). 
Case 2 : Let target feature Y have two categories. For all Y=0,  there is a high correlation between two variables X2 and X3. But no or very low correlation between X2 and X3 for another category of Y(at Y=1). 
Usually we retain one of X2 Or X3 but what should be the approach in such cases?

First, it is good to know that Multicollinearity problems are adressed by algorithms, but every algorithm has its own handling of multicollinearity. So you can be assured, that different algorithms deal with it in a different way, although they might be from the same family, like XGBoost, Catboost, LightGBM GradientBoosting from sklearn or the EBM by Microsoft.
From what you describe it is not even sure to keep X2 AND x3 because the collinearity to one of the categories from X1 (in your case 0) may already state that X2 and X3 basically describe category 0. So i would even think about that.
Also, which variable to keep also relies on the problem at hand. For a pure prediction task, the choice depends on what variable helps in achieving on average (out of lets say 100 models with random seeds etc.) a better forecast.
In that case its irrelevant to choose X2 over X3 or vice versa, then it is more a problem of how costly it is to acquire the certain variable for prediction. Because you only want to predict not explain, thus the relationship may also be irrelevant, as long as your model hits the spot.
If the task is explainability/causality then it is a more delicate aspect. As the choice of the variable shall represent a reasoning in your model. This is mostly, where business knowledge of your respective field, you are working on, is valid source. There was a ML/DL process a few months ago in the press about chemical engineering, where they found automatically good models with high correlated materials for batteries I believe, but the correlation didnt made sense. They needed an expert to decide upon what made sense or not.
So for X2 or X3 it depends on what these variables represent in real life.
I for example prefer a model, that knows if two variables are exact copies of each other (100 % collinear), both variables share an equal part on Y. The only algorithm capapble of that atm is the Explainable Boosting Machine with the RoundRobinProecdure.
