Shale formations often contain a high proportion of clay minerals, which, upon contact with drilling fluid, undergo hydration expansion. This leads to wellbore instability, a problem that poses significant challenges globally. This study aims to investigate the variation of mechanical properties of shale with respect to hydration time. We employ an empirical model that relates shale strength parameters to the time of drilling through geological formations. Additionally, we consider both shear failure along the wellbore boundary and shear sliding along bedding planes in the analysis. We establish a predictive model for wellbore instability in shale formations. The model quantitatively analyzes the variation of wellbore collapse pressure with drilling time. The research findings indicate that, when the influence of bedding is considered, both the wellbore collapse pressure and the optimal well trajectory undergo significant changes, in addition, for some wellbore trajectories, the collapse pressure can increase by more than 30%. Therefore, it is essential to account for the influence of bedding in wellbore stability analysis in shale formations. As the bedding dip angle changes, both the numerical values and distribution range of wellbore collapse pressure and the optimal well trajectory change noticeably. Changes in bedding dip direction, however, do not affect the numerical values of collapse pressure but do influence the distribution region of the optimal well trajectory. Thus, in wellbore trajectory design within shale formations, it is crucial to determine the orientation of bedding and adjust the well trajectory accordingly to enhance wellbore stability. Furthermore, shale hydration does not impact the optimal well trajectory for a block, but with prolonged hydration, the minimum drilling fluid density required to maintain wellbore stability gradually increases. This suggests that hydration intensifies the weakening effect on bedding plane strength. The research results are helpful to understand the effect of hydration on shale wellbore stability and ensure shale wellbore stability during drilling cycle.