Bacteria can enter the joint by:

The bloodstream from an infection elsewhere (most common)
Direct penetration into the joint (arthrocentesis, arthroscopy, trauma)
A surrounding infection in the bone or tissue (uncommon, from osteomyelitis, septic bursitis, abscess).Microorganisms in the blood may come from infections elsewhere in the body such as wound infections, urinary tract infections, meningitis or endocarditis. Sometimes, the infection comes from an unknown location. Joints with preexisting arthritis, such as rheumatoid arthritis, are especially prone to bacterial arthritis spread through the blood. In addition, some treatments for rheumatoid arthritis can also increase a persons risk by causing an immunocompromised state. Intravenous drug use can cause endocarditis that spreads bacteria in the bloodstream and subsequently causes septic arthritis. Bacteria can enter the joint directly from prior surgery, intraarticular injection, trauma or joint prosthesis. Risk factors
In children, although septic arthritis occurs in healthy children and adolescents with no co-occurring health issues, there are certain risk factors that may increase the likelihood of acquiring septic arthritis. For example, children with renal osteodystrophy or renal bone disease, certain hematological disorders and diseases causing immune suppression are risk factors for childhood septic arthritis.The rate of septic arthritis varies from 4 to 29 cases per 100,000 person-years, depending on the underlying medical condition and the joint characteristics. For those with a septic joint, 85% of the cases have an underlying medical condition while 59% of them had a previous joint disorder. Having more than one risk factor greatly increases risk of septic arthritis. Age over 80 years
Diabetes mellitus
Osteoarthritis
Rheumatoid arthritis.
The most common cause of arthritis in these joints is intravenous drug use. Usually, only one joint is affected. More than one joint can be involved if bacteria are spread through the bloodstream. Prosthetic joint
For those with artificial joint implants, there is a chance of 0.86 to 1.1% of getting infected in a knee joint and 0.3 to 1.7% of getting infected in a hip joint. There are three phases of artificial joint infection: early, delayed and late. Early – infection occurs in less than 3 months. Usual signs and symptoms are fever and joint pain, with redness and warmth over the joint operation site. The mode of infection is during the joint implant surgery. The usual bacteria involved are Staphylococcus aureus and gram negative bacilli. Delayed – infection occurs between 3 and 24 months. There would be persistent joint pain, due to loosening of the implant. The mode of infection is during the implant surgery. Common bacteria are coagulase-negative Staphylococcus and Cutibacterium acnes. Late – more than 24 months. It is usually presented with a sudden onset of joint pain and fever. The mode of infection is through the bloodstream. The bacteria involved are the same as those in septic arthritis of a normal joint. Cause
Septic arthritis is most commonly caused by a bacterial infection.