OK, sounds like the detent and pin are in place. In that case it sounds like the takedown pin itself may be the problem. There is a groove in the rear of the pin where the detent is, and there is a small "hole" or depression on each end of the groove where the detent is supposed to drop in with a pronounced "click" to hold it either in the open or closed position. It sounds to me like the hole that the detent is supposed to drop into to hold it in the closed position is either not there at all, or is located wrong. Easiest fix would be to replace the takedown pin. Another possibility is the hole in the lower receiver that the detent and spring are in could be located incorrectly. In that case you can modify the takedown pin with a Dremel (and a really tiny burr bit) to compensate, or have the manufacturer of the lower receiver correct the problem (most likely by replacing it).
Hope this helps...or even makes sense.
ETA: After thinking for another second or two, it's still possible that the detent is missing but the spring is still there and keeping the takedown pin from coming all the way out. First thing to do is verify the detent is present.