Everything in that program’s window is under the program’s control. Hitting the X sends an event to the program telling it to commence its shutdown procedure (could be a bunch of cleaning up and stuff it likes to do before it quits). But if the program is hung or unresponsive, it won’t do anything in response to hitting the X. That shutdown part of the program is as frozen as the rest of it.
Using the OS to end the program just kills the program’s entire process from above.
Latest Answers