Neurological pain (NP) is always accompanied by symptoms of depression, which seriously affects physical and mental health. In this study, we identified the common hub genes (Co-hub genes) and related immune cells of NP and major depressive disorder (MDD) to determine whether they have common pathological and molecular mechanisms. NP and MDD expression data was downloaded from the Gene Expression Omnibus (GEO) database. Common differentially expressed genes (Co-DEGs) for NP and MDD were extracted and the hub genes and hub nodes were mined. Co-DEGs, hub genes, and hub nodes were analyzed for Gene Ontology (GO) and Kyoto Encyclopedia of Genes and Genomes (KEGG) enrichment. Finally, the hub nodes, and genes were analyzed to obtain Co-hub genes. We plotted Receiver operating characteristic (ROC) curves to evaluate the diagnostic impact of the Co-hub genes on MDD and NP. We also identified the immune-infiltrating cell component by ssGSEA and analyzed the relationship. For the GO and KEGG enrichment analyses, 93 Co-DEGs were associated with biological processes (BP), such as fibrinolysis, cell composition (CC), such as tertiary granules, and pathways, such as complement, and coagulation cascades. A differential gene expression analysis revealed significant differences between the Co-hub genes ANGPT2, MMP9, PLAU, and TIMP2. There was some accuracy in the diagnosis of NP based on the expression of ANGPT2 and MMP9. Analysis of differences in the immune cell components indicated an abundance of activated dendritic cells, effector memory CD8+ T cells, memory B cells, and regulatory T cells in both groups, which were statistically significant. In summary, we identified 6 Co-hub genes and 4 immune cell types related to NP and MDD. Further studies are needed to determine the role of these genes and immune cells as potential diagnostic markers or therapeutic targets in NP and MDD.