Sexually transmitted diseases (STDs), particularly chlamydia and gonorrhea, can lead to hydrosalpinx by causing infections in the fallopian tubes. These infections often result in inflammation, which can damage and scar the fallopian tubes. This scarring can block the tubes, preventing proper drainage of fluid that builds up, leading to hydrosalpinx.