Take two processes A and B. Also, take the general guideline when a process is trying to access a file system, It needs to acquire a resource lock, and then access the file system. When the resource lock is acquired by a process, no other process can acquire the same resource lock, and hence, cannot access the file system. Also, the locks are handled by semaphores with wait forever property, so when a process tries to acquire a lock and it's not available, it's going to wait forever at that point, without proceeding(in a pending state).
Process A is going to access filesystem A. It acquires lock for it, and is working on it. Due to context switching, it goes out of context.
Now process B is going to access filesystem B. It acquires lock for it, and is working on it. Due to context switching, it goes out of context.
Now process A, without releasing the lock for file system A, tries to acquire lock for file system B. The lock is not available, so it is going to enter pending state, and does not proceed further.
Now process B is scheduled, which again, without releasing the lock for file system B, tries to acquire lock for file system A. The lock is not available, so it is going to enter pending state, and does not proceed further.
So one process holds the resource needed for the other process to proceed further, so both processes are now deadlocked.