How can wifi penetrate through walls when visible light can't?
Different molecules and different crystalline structures have frequency dependent absorption/reflection/transmission properties. In general, light in the human visible range can travel with little absorption through glass, but not through brick. UV can travel well through plastic, but not through silicate-based glass. Radio waves can travel through brick and glass, but not well through a metal box. Each of these differences has a slightly different answer, but each answer is based on molecular resonance or crystalline structure (or lack thereof) or electrical conductivity.
Bottom line: There isn't one general answer for why $\lambda_A$ goes through material X but $\lambda_B$ doesn't.
The way light, radio waves or microwaves interact with matter is through electromagnetic interaction with the microscopic charged particles. Different types of excitation can happen with these charges depending on the energy of the photons constituting the radiation. With increasing energy the radiation can cause molecular rotations, molecular vibrations, electronic polarization, electronic excitation, ionization, atomic excitation and so on.
The wifi operates in the microwave frequency and this can only generate rotations or maybe vibrations to the molecules. In the process of penetrating the material and interacting with the molecules, the microwave loses energy through heat. However in general this losses are small and the microwave can penetrate a long distance into the material.
Light on the other hand interacts with matter via electronic excitation or electronic polarization. There is a quite general theory that describe the electrons in solids called band theory. According to it the electrons have energy levels distributed along energy bands with the range of a few electron volts. Moreover, these bands are separated by "forbidden levels" called band gaps. For conductors the last band (valence band) is only partially filled whereas for insulators it is completely filled. This fact is crucial to the electric and optical properties of the material.
Given the frequency $\nu$ of the photon, its energy can be calculated from $$E=h\nu.$$ In particular, the photons composing the visible light have energies approximately between $1.8\, \mathrm{eV}$ (red light) to $3.1\, \mathrm{eV}$ (violet light). If you incide light in a material whit band gap of less than $1.8\, \mathrm{eV}$ then every photon is able to excite an electron from the valence band to the conduction band. The electrons then emit this photon and the overall effect is that the material is opaque. On the other hand if the material has a band gap greater than $3.1\, \mathrm{eV}$ no photon (in the visible) can be absorbed. The material is then transparent to light, such as a glass. There is also absorption of light in transparent material through electronic polarization so a very thick glass transmit less light.
If you keep increasing the energy of the photon, let us say to the ultraviolet regime, then even for glass there will be valence band-conduction band transitions and the glass is as opaque to UV as wood is to visible light.