How does static port measures the static pressure? I have always thought that there is a probe or sensor kind of thing inside the static port so that it "measures" the static pressure and compare to other pressure sources for airspeed, altitude, and VSI reading.

But my other pilot friend recently told me that the way static port works is because of the air actually flows in and out of it.

For example, when you climb, the ambient pressure decreases so the air will flow out of the static port until it reaches equilibrium, which causes the static pressure inside the casing of altimeter to decrease and the altimeter shows an increase in altitude.

Tried to find answers about how static port work online but did not find a satisfying explanation...

If anyone knows more on this topic please share your opinion.
Your friend is correct. It's situated in a spot where the dynamic pressure is non-existent or minimal such as on the rear side of the fuselage on a Cessna 172 where it's able to measure the ambient pressure. This pressure is then either fed by tubes to their respective instruments (ASI, Altimeter, and VSI), or on modern aircraft, it is read by a transducer (or analog to to digital interface units - A/DIFU) which converts the reading to electronic data which is then fed to the air data computer.