Can knee swelling cause locking of the joint?

Other way around. Locking of the knee joint is usually caused by a loose or torn cartilage (meniscus) in the knee - so a torn cartilage causes swelling, then the torn piece can cause locking.