The vulnerability of karst ecosystems and the weak mechanical performance of caves pose hidden risks in railways, leading to increased karst collapses. To analyze karst collapse as a railway hazard, we selected the Beijing-Guangzhou Railway, China line to identify karst features using the multi-source frequency domain method for its operational advantages. We also used ABAQUS to numerically analyze the factors (dynamic loading, groundwater fluctuations, over-burden thickness) affecting the collapse mechanism. The study reveals diverse stratigraphy, transitioning from a Quaternary layer to stable rock formations. A notable finding is that the presence of a karst cavity in the railway embankment significantly increases the vertical dynamic displacements, particularly within the soil layer, by 72%, highlighting the significant impact of karst sections on soil dynamics. The study also reveals that due to the groundwater table fluctuations from subsoil surface to subgrade surface, the maximum displacement increases by 73% in the subgrade section of the railway embankment. We consider soil overburden thickness to validate confirming reliability through field data and theoretical study. Findings offer crucial insights for managing karst hazards, enhancing railway safety, and ensuring durable infrastructure in challenging geological conditions.