Entanglement dynamics of a hard-core quantum gas during a Joule expansion