Most people think it came from an actual bug (usually a moth) being found in the circuitry of one of the first computers.
But it didn't.
Here's an interesting article on it:
https://www.computerworld.com/article/2515435/app-development/moth-in-the-machine--debugging-the-origins-of--bug-.html
Back in the early 1960’s, NASA used to use an old Volkswagen beetle transport computer tapes from one building to another. They nicknamed the car the “Computer Bug”. During the Apollo program, the little car was constantly breaking down. It spent more time in the shop than it did doing its job. Therefore, whenever there was a problem with the main computers they jokingly called it a “computer bug” in reference to that little car.