Gear down invokes two penalties: increased drag and reduced speed.
On modern airliners, gear down can add up to 50% more drag, so that's not an inconsequential number.
Also, the landing gear doors being open, or even partially open in the case of airliners that have some streamlining of gear in the down position, limits the maximum speed to a very low number, beyond which the doors will be torn off by the slipstream, possibly doing some nasty damage to the aircraft in the process.
That also limits the pilot's options in an emergency situation, like needing to descend quickly, or accelerate to avoid a dangerous condition, like stalling.
Finally, one has to ask... if the gear fails to retract, what else is wrong? Maybe nothing, maybe something. Could be a bad switch, could be a hydraulic leak that might also affect the flight controls, could be a piece of metal digging into the wiring harness that might later affect critical systems or start a fire. For sure, the aircraft has a problem that's out of the ordinary.
In the end, it's up to the pilot to make the call, but a failure of the gear to retract on a commercial airliner usually means getting the plane landed as soon as practical... i.e. dumping enough fuel to get down to a safe landing weight and getting clearance.
It's a lot easier to change planes or find and fix the problem, than to lose the aircraft and its passengers.