Go to Edit->ProjectSettings->Physics.
There you have the collision matrix. With the checkboxes you define which layer collides with which.
Edit: The collision matrix isn't supposed to change all existing contacts in realtime. If we were to do this, we'd have to re-evaluate every single contact in the world which could be very expensive and is easily abused. Check this. So you can try to change the collision matrix with code, you can probably do so, however I would suggest to handle the collisions thinking of them in terms of space, not time.
By this I mean that you try to detect the collision not at the time when your car is out of track, but, with the corresponding layers and colliders, detect the collision where its out of track.
If you are still into changing the collision matrix in runtime you can try check out the docs
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…