Before sleep in bed, why does middle back have spasms lasting 3 or 4/minutes 1 or 2 times/weekly?

It depends. Back spasm can signal overuse, stenosis (narrowing), or instability. At night you go from vertical to a horizontal and the curve (lordosis) in the lower back is subject to forces that tend to straighten it out. If it is too tight or too lax, the nerves can be irritated; causing back pain. Try a pillow beneath the small part of your lower back. If it keeps hurting, get examined & get some x-rays.
Strech. Mid back spasm may occur from overuse or arthritis or a disk injury. Usually elevating your knees to the 45degree position takes pressure off the low back and hips and can reduce back spasms. Nsaids may help and low level heating pad can also relieve spasms.