Shaanxi is very remote, in the deep interior of China, which is hard to fight in. The Japanese never attacked Chongqing either. (Chongqing was bombed, but so was Yan'an.) Progress into this region was halted due to Chinese victories such as Wuyuan.
The CCP were not as big of a threat
The CCP started the war with a very weak base, and even at the end of the war, they were a fraction of the strength of the Nationalists. In this situation, it is better to attack the stronger of the two enemies. There was a brief flare-up during the Hundred Regiments Offensive and the subsequent Three Alls Policy, but for the most part there was a stalemate between CCP and Japan.
Subduing China was not a priority
Japan's WWII aggressions were opportunistic in nature. Initially they thought that China could be subdued by taking its capitals, or by winning a decisive battle. That didn't work: Nanking and Wuhan were taken but the Nationalists didn't capitulate, and they also managed to preserve their troops through the war. Instead, Japan focused on South East Asia and the Pacific Theatre.
Lack of resources by Japan
By the latter half of the war, there was in fact a plan to invade the wartime capitals of both the Nationalists and CCP. This plan was frustrated by their lack of resources (due to the deteriorating Pacific War) and the increasing success of attacks by the "Flying Tigers" and its impact on daytime troop movement. The plan was finally shelved in favour of Operation Ichi-Go - the forces gathered in North China originally intended for the plan were redirected to Ichi-Go instead.
The Chinese Theatre was a typical truel, in which the best strategy for the stronger two sides is to eliminate each other first, and for the weakest side to sit out until they are left head-to-head with the survivor. This is indeed what happened. This reason isn't historical, but it is food for thought nonetheless.