What is required in a hollow piece of tube of any shape to resonate and generate musical stable pitches and harmonics?
user65726's answer has some of the basics, but to expand on that a bit:
The question asks for two things, which do not necessarily always come together: "musical stable pitches" and "harmonics."
First a little background. To be clear, harmonics are not necessarily the same as overtones. A harmonic is an overtone which is an integer multiple of a fundamental frequency. Most 3-dimensional items do not resonate harmonically. That is, they often have many modes of vibration that do not necessarily relate as integer multiples of some frequency. If you strike a random hunk of metal with an odd shape, what will often result is a sort of "clangy" noise where different frequencies (produced by the different modes of vibration) all intermingle.
Many standard musical instruments instead depend on harmonic overtones. The human auditory apparatus tends to group integer multiple overtones into a single "pitch" that we experience as the "fundamental." For "clangy" sounds produced by 3-D objects (e.g., church bells), people may hear multiple pitches sounding together, rather than a single stable fundamental.
I'm assuming from the way the question is worded around "harmonics" that it is primarily interested in musical tones that generally create a single, stable pitch.
In that case, there are two possible kinds of resonators with a "tube of any shape."
The first kind is similar to most musical instruments that are tube-shaped (e.g., most brass and woodwind instruments, organ pipes, etc.). Tube-shaped musical instruments resonate not only at a fundamental frequency, but also are close enough to one-dimensional tube approximations that they can generate multiple standing wave patterns that produce harmonics. To generate good standing waves at multiple harmonic frequencies, the interior walls of the tube should be rigid and relatively smooth without sudden changes in diameter. Either open-ended tubes or tubes stopped at one end can be used to produce standing waves (with different frequencies produced).
Straight cylindrical or conical shapes can be used (as are found in various musical instruments). Musical instruments typically use a circular cross section for the interior walls, but it's possible to use other bore cross sections (like triangles, squares, etc.) through the tube and still produce stable harmonics, though the exact frequency spectrum produced may vary a bit.
There are some limitations on this type of tube. As noted, the material must be somewhat rigid. Otherwise, damping of the wave energy will occur too quickly and a standing wave may not be established. The length must also be sufficient relative to the width to set up a standing wave. One could imagine trying to blow across a small bowl or very short wide tube -- while it may be possible to create a high-pitched "whistle" in some cases, the sound likely won't be very musical and harmonic.
Another consideration is whether one is creating sound by blowing air (or using the resonance from air motion) vs. striking the instrument. In general, a percussion instrument created by a tube that is struck will create most of its sound through the vibration of the material rather than the air column inside of it. Since a tube like this will behave as a three-dimensional object rather than a one-dimensional air column (with its standing waves), the resulting sounds are much more inharmonic ("clangy"). Chimes and tubular bells are an example of this type of resonance, where the sound of the metal vibration is much louder than any air column resonance. Church bells and handbells are often even more inharmonic, due to their more complex shape combining two-dimensional and three-dimensional modes of vibration. Musical tones may be produced by these instruments, but they are less good at producing proper "harmonics" and may emit multiple distinct inharmonic pitches at the same time (sometimes referred to by various terms like "strike tone," "hum tone," etc.).
Moving on to the second type of resonator: If a harmonic sound is not required and only a stable fundamental resonance pitch is sufficient, a wider variety of closed tubes can be used to produce a Helmholtz resonator, also referred to as a vessel flute. In a Helmholtz resonator, the overall shape of the tube is not as important as the fact that there is a relatively narrow opening, whereby a wave pattern is set up at the opening and depends primarily on the total volume of the closed tube/vessel. If the opening also has a small narrow tube before entering the wider vessel, the characteristics of that tube may also play into the way the instrument resonates.
This type of resonance is responsible for the kind of sound which emerges from an irregular closed tube or vessel, like a bottle. When air is blown across the opening, the resonance of the vessel can produce a sustained tone. In this case for irregular shapes, patterns of harmonic standing waves are generally not created. Thus overtones are typically hard to produce and the sound tends to be mostly a single fundamental pitch. (These sorts of resonators were actually used historically to do a sort of mechanical Fourier analysis, as they would only resonate at pure tones that were then used to match up to a more complex sound.)
The key general feature for getting harmonics is that the sound generating mechanism be (effectively) 1-dimensional. Whether straight, like a flute, or bent up, like a bassoon, all pitched woodwinds (and brass, and strings...) have a resonator/oscillator that is much much longer than its size in the transverse directions.
— By harmonics I mean overtones that are integer multiples of a fundamental frequency.
The two most important requirements for resonance are a stable enclosure volume (small or large) and air particles for an instrument that uses air to produce a tone, but solid materials also resonate, just consider a chime or cymbal, and size is still an important factor to consider when choosing a preferred tone. The shape of the internal volume may affect the sound and materials used to create the enclosure also come into play, consider a violin or guitar, but the two things that determine whether or not a tone is created or amplified by resonating air particles, is the internal volume of the resonant chamber and the air particles themselves.
The tube needs to be able to entertain a standing wave without too much loss of energy. A consistent cross section (preferably circular and of constant diameter, with comparatively inflexible walls) and two ends with significant reflection of sound travel in a "mode" of the tube (because they are closed or significantly wide open) are usually used.