There's a whole Einsteinian General Relativity answer here that I'll let other people give. But your question does remind me of a Newtonian idea. Basically after the speed of light was discovered but before Einstein came along, people asked your exact question: "What if a star is so dense that it's escape velocity exceeds the speed of light?" The answer is Dark Stars (AKA Newtonian Black Holes). To be clear, these objects don't exist in the real world, but they are fun to think about.
BlackHoleTopologist t1_jdis0cu wrote
Reply to Could a black hole just be a big neutron star that just has gravity so high light cant escape? by SlyusHwanus
There's a whole Einsteinian General Relativity answer here that I'll let other people give. But your question does remind me of a Newtonian idea. Basically after the speed of light was discovered but before Einstein came along, people asked your exact question: "What if a star is so dense that it's escape velocity exceeds the speed of light?" The answer is Dark Stars (AKA Newtonian Black Holes). To be clear, these objects don't exist in the real world, but they are fun to think about.