I apologize for the following somewhat rambling and long answer. Editing it down would take more of my time, and I'm not really sure whether I'm even addressing what you're interested in.
What you're asking is a really complicated question to explain in any depth, so hopefully some of this gets at the kind of stuff you're thinking about. Since your comment clarified that you're interested in 18th-century style and melody, that's what I spend most of the time on here.
First, let me begin by acknowledging your question gets at the heart of a real hole in current music theory pedagogy, which tends to emphasize harmonic (and, to a much lesser extent, rhythmic) concerns over melodic ones, along with deemphasizing dynamics, articulation, tone/timbre, and a variety of other musical parameters.
That said, the closest match to what I think you're trying to get at in music theory curricula tends to be covered within the notion of tonal counterpoint. While books on that subject don't often make melody-writing the central focus, the very idea of counterpoint (as opposed to simple voice-leading) presumes the notion that lines (i.e., melodies) are important as part of creating a musical texture. Implicit in the concept of tonal varieties of counterpoint is that the melodies are coming together to generate tonality, which is intimately tied in with harmonic structure.
Michael Curtis's great reading suggestions are a place to start, though you end up there (as with most "tonal counterpoint" books) with a focus on eighteenth-century European style, often even in very specific places within Europe. Because if you really want a detailed method to use melodic implication to outline harmony, you probably need to specify a very particular musical style, as the potential harmonic implications of a melody as harmonized by Mozart may be quite different from the possible ways that a jazz composer or a modern rock band might view the same melody (and the types of harmonies that might work with that melody).
But from the framing of your question -- which utilizes an 18th-century source -- I'm going to assume that's where you want to begin. Again, tonal counterpoint sources tend to revolve around this style too.
While you have repeatedly said in comments that you "reject the premise" that composers utilized "harmonic skeletons," if you're talking about the 18th century, it was very much part of the grammar of how to compose, along with other things. (I would, however, qualify that to say that they weren't really "harmonic" in sense of how we now understand "harmony" as triads and chord progressions -- more like patterns of bass lines and figured bass and cadential idioms and such.)
Yes, obviously it is possible to imply harmony via melody. But it's not always an exact match. In reality, composition in the tonal styles of the 18th century was often more like a sort of crossword puzzle (to use an analogy): the horizontal melodies and bass lines had to interconnect with the underlying implied harmonies. Neither the vertical nor horizontal methods could work well without the other. They were generally composed together (with exceptions in certain genres that might start with a predetermined melody or predetermined bass line). A melody may have been composed with possible harmonies in mind, then filling out the harmony may have led to changes in melody, and the same interplay and interweaving continuing as if you're filling in a crossword puzzle, sometimes making errors horizontally or vertically and then fixing them until all the bits align well.
To try to summarize how to imply harmony with the use of melody is a difficult task. Michael Curtis gets at some of it with his Do-Re-Fa-Mi example. But let me begin by laying out a few tendencies and guidelines to begin:
Harmonic rhythm (i.e., how often and where chord changes occur) and phrasing are important to consider when beginning to draft a melody. Having unidiomatic harmonic rhythm is often the place I've seen students struggle the most with in imitation of 18th-century style. It's not enough to string together tonic-predominant-dominant-tonic. You need to have a consistency to where chord changes occur (often on relatively strong beats) and how often chord changes occur (which can vary, but often does so in predictable and idiomatic ways). Students who learn harmony from chorale style often have a completely wrongheaded idea that every melody note should match up with a chord. Instead, outside of Bach chorales and hymn style, most melodies go for several notes or even many measures while retaining a sense of the same underlying harmony. Harmony changing every quarter note (or even faster) in 18th-century style for extended sections of a piece is quite rare. (And when it does seem to change faster, it's often in idiomatic diminution patterns that are articulating a broader pattern of harmony like a sequence moving at a slower pace.) If you want to craft a good baroque or classical melody, you must have a sense of how a phrase functions, how to use sequences, how to create cadences, etc. melodically. If you don't do this, the harmony you match with it won't sound right, regardless of what harmony the notes may "imply" in some sort of abstract sense.
Cadences in 18th-century style are very strongly determined in potential melodic motions, so you don't have much choice as to what melodies will do there. This is one place the question's notion of using the root or third of a triad is important. If you scan a lot of music from that era, you'll almost never see a cadence to tonic ending on scale degree 5. It's almost always to 1 or 3. On the other hand, such rules are not universal, as most of 18th-century music was written before notions of the triad were strongly held as they are today, so composers didn't often think in those terms. Cadences had melodic patterns that were often first used centuries before and determined long before "tonal" harmony was a thing. So, while authentic cadences are almost never to scale degree 5, half cadences are very frequently to scale degree 2, i.e., the fifth of the V chord. This begins to get at the problem you'll start to encounter if you try to generate "rules" for articulating harmony through melody -- it's a very complex process that does have guidelines, but they're very dependent on lots of stylistic idioms.
It's obviously not as simple as matching a particular scale degree to a particular harmony. Again, melodic idioms often create large parts of the usable melodic language of 18th-century style. Books like the Gjerdingen and Sanguinetti you were discussing with Michael try to capture some of the different melodic patterns that were taught and elaborated (e.g., through diminution, but also through other variants like chromaticism) while outlining common harmonic phrase frameworks.
Since there are entire books written about this that only scratch the surface, I can't possibly summarize it all here. But to give a sense of where this starts: certain melodic motions determine harmony more specifically (and key as well). Semitones are often quite important in this regard. An upwards semitone motion tends to imply a "dominant to tonic" type motion (where various dominant chords may be substituted, or a "deceptive cadence" style resolution to a local "submediant" chord may also work), effectively a "ti-do" in modern solfege. This may or may not be in the primary key; using it on another note in the scale is an effective method at modulation.
The other primary semitone motion is "fa-mi." A descending semitone motion generally is used to also create a local sense of dominant-tonic and again can be used with chromaticism to elicit a local tonicization or modulation. On occasion, the descending melodic semitone can imply "le-sol" and is helpful in creating a minor mood too (usually pointing toward V instead of i).
While semitone motions aren't the only way, they are a useful example of seeing the strongest power of melody to drive harmony. If you want to learn to modulate in a melody, learn to use ti-do and fa-mi to other keys. If you want to learn how to articulate a key (or modulation) clearly in two-voice counterpoint, combine these into a tritone that resolves to your destination key. (The tritone resolution will uniquely identify the local key, which is important for strong harmonic implication and clear resolution.) That's the way the baroque and classical composers would have viewed all of this, not as notes from "chords," but as melodic idioms that have specific resolutions -- and from those resolutions come harmonic implications.
Beyond cadences, which had very regulated and expected harmonic and melodic patterns, earlier parts of phrases were often conceived by utilizing stock melodic patterns and variants on them which had strong stereotypical harmonic patterns through their repeated usage. At other times, a melody might be crafted to go along with standard harmonic patterns that follow, for example, an ascending or descending bass line (very common idioms). Even though a skilled composer would develop variants of these ideas to the point that you might not even recognize them as variants, many phrases are based in these patterns that students would practice over and over again. Melodies that conformed to these patterns would just "sound right" because they reflected stereotypical harmonic patterns in the language of the time. A composer could literally come up with dozens or even hundreds of ways to vary
a melodic pattern over these stereotypical harmonic sequences (once you understand the skeleton), to the point that writing a melody in this manner becomes instinctive.
Another question that comes from the Kirnberger example in the question and which was brought up in comments is how to deal with non-harmonic tones. The brief answer is: that's why introductory books on harmony and counterpoint spend so much time on regulation of dissonance. Non-harmonic tones in 18th-century style primarily occur on weaker beats or off beats. They are rarely leapt to or leapt from. (Doing so tends to emphasize them and make them feel more likely to be chord tones.) If they are leapt to or leapt from, there are often idiomatic guidelines about when this happens. For example, escape tones (one of the very rare examples where you leap from a dissonance in 18th-century style) almost always occur on an offbeat with a rise by step and then a leap down by third. It's quite rare to see escape tones that do other things (though they do occur). Appoggiaturas, where you leap to a dissonant tone and then almost always resolve down by step, also tend to occur in idiomatic locations and in relationships to clear unambiguous potential underpinning harmony.
And the details can go on and get very complicated very fast. The general grammar of non-harmonic tones in this style highlights suspensions, weak-beat passing tones, and weak-beat neighbor tones. But even among these, there are subtleties. For example, descending accented passing tones occasionally occur. In the 18th century style, ascending accented passing tones are rarer. Lower neighbors (and I'm talking about complete neighbor tones here) are much more common than upper neighbors. Accented (or relatively accented) neighbor tones are quite rare. Suspensions are quite common but tend to occur in certain parts of phrases, over certain harmonies (or in sequences), and are prepared and resolved correctly (which involves not only proper melodic and harmonic context but also correct rhythms and durations). A lot of these naturally follow from melodic idioms that don't disturb underlying harmony in certain contexts. When the more rare types of dissonance occur, it's usually where the implied harmony is very clear (by use of idiomatic progressions and idiomatic melodic elements), so more freedom can be used with non-harmonic tones.
To summarize the last couple points: the regulation of dissonant notes that are non-harmonic is arguably much more important in the creation of a melody that strongly implies a good harmonic progression than the consonant notes. If you don't understand how to regulate dissonance, you can't differentiate between which notes of the melody sound like "part of the chord" and which don't. And, as I've tried to get at here, it's not just about putting chord notes on strong beats (though that's a large part of it).
Let's go back to the Kirnberger example in the question. What's wrong with this melody? Again, let's start with harmonic rhythm. Melodies at the time of Kirnberger want to have a clear sense of harmony articulated on strong beats, with possible faster harmonic rhythm at times (usually governed by more strict rules, i.e., following idiomatic patterns like cadences, sequences, etc.). When you begin a melody C-D in 4/4, presumably starting on tonic (without other context), the D is either going to be a passing tone or articulate some other chord.
I'll consider C major as the putative key here (though with this beginning, I suppose A minor isn't out of the question, but it raises similar problems). In that case, in 18th-century style, basically the only way to harmonize Do-Re out of context is tonic-dominant. Various dominants could be used depending on what happens next, but that's basically what this implies, assuming a harmonic rhythm on the quarter note.
But really, what we want to feel in 18th-century style with such a progression is a return to tonic on the 3rd beat (relatively strong beat), effectively making a sense of "static" harmonic rhythm that "remains" on tonic overall, despite a brief divergence to dominant on a passing chord or something on beat 2. And that's about the only place where dominant can go.
None of that can happen with an A on beat 3. Michael's chosen "fix" works because it effectively uses an idiom -- a double-neighbor or changing tone -- that circles around the return to tonic on beat 4. This is actually closer to a later 18th-century idiom and would generally occur with a more spread-out harmonic rhythm over 2 bars or 4 bars rather than in a single bar (particularly as an opening to melody), or it could be part of a pattern of sequential "climbing" notes I suppose in diminution. (Lots of melodic weirdness and weakness can sometimes be overcome by repeating a melodic figure a number of times in sequence.)
But perhaps I'm getting bogged down in details. The problem with the Kirnberger melody is that it doesn't have any rules for creating an effective underlying and consistent harmonic rhythm, which therefore doesn't allow the correct elucidation of the rules governing the regulation of dissonant notes. Which means we can't tell which notes are supposed to be supporting a "strong" underlying chord vs. perhaps a passing tone or neighbor tone or some other non-harmonic thing.
The first rule of 18th-century melody writing is to articulate the difference between harmonic and non-harmonic tones effectively. To do so, one needs to adopt all the harmonic rhythm and idiomatic progression guidelines that I (and Michael) have been discussing. When I look at the Kirnberger example I see a melody that starts on tonic, maybe? Then a potential passing tone on D that suddenly leaps away (a no-no -- don't leap from a note dissonant with the underlying implied strong harmony; also stepwise motion followed by a leap in the same direction is somewhat unusual idiomatically in 18th-century style when ascending, unless there's strong harmonic support, which there obviously isn't here). Then -- huh? What to harmonize A with? IV? Really? Then leap down to E, which implies I. According to the "rule" articulated in the question about emphasizing chordal thirds and roots, this should work well to create a sense of IV-I, but it absolutely is unidiomatic melodically in this case for 18th-century style. (Again, these "rules" aren't so simple to articulate.)
Then we leap up to the leading tone B, which notably doesn't resolve (thereby denying that semitone motion which is so critical to using melodic to articulate harmony). And then we just fall down through the notes of a V chord, maybe? (In general, too many leaps are in this melody: unless the melody is a general arpeggiated pattern with "multiple voices" embedded, i.e., compound melody, 18th-century style tends toward more stepwise motion, particularly to connect harmonies.) Except if our harmonic rhythm in the first bar was supposed to be every quarter note, 18th-century harmony wouldn't generally "put on the brakes" a measure later to have the same chord implied over three notes. Which means retrospectively any sort of potential harmony for the first bar makes no sense whatsoever. (If anything, we generally see acceleration of harmonic rhythm through a phrase in 18th-century style, getting faster when approaching a cadence; the slow-down that happens here is quite rare and weird.)
I'm trying to give you a sense of some of the concerns that need to go creating a sense of harmony from melody come together. Yeah, it's really quite complicated. And this is in a relatively well-studied somewhat circumscribed style of 18th-century music. If you start asking how melodic implications can generate harmony in jazz or pop music, there are completely different stylistic factors at play (though elements of harmonic rhythm, phrase structure, use of dissonance, etc. are still going to be important in how to match melody to harmony in many other styles too).
I think most textbooks shy away from trying to explain the way to create melody because the details do get complicated so fast. And, unlike with the basic "rules" that are taught about harmonic progressions and voice-leading, the "rules" of melody writing beget many complexities that have to do with not only the scale degrees of the notes and their rhythms, but also placement in metric accent (coupled with harmonic rhythm), agogic accents (i.e., accents created by duration), accents created by shift in melodic register, placement of non-harmonic tones and relationship to the consonances around them, etc., etc.
There's a reason why so-called "species counterpoint" was often taught (and studied by many composers in the 18th century): if you work on creating smooth melodies that are consonant on strong beats, that can get you a long way. Then you introduce diminution, which teaches you patterns to build in shorter note values and non-harmonic tones around a skeleton of consonant strong beats. With a good teacher, you learn to do all of this in the context of many, many good cantus firmi/basslines that a student will gradually absorb with idiomatic cadential motions, etc. Then you start learning how to "spin out" ideas, to write connecting sequences that fill in parts of phrases or modulate to other keys. Then you learn how to interpolate those within the stock phrases and progressions and patterns you've been learning. Along the way, you begin to see the use of things like "tendency tones" (those semitone motions I discussed) and other melodic idioms.
And only then, after you've truly mastered the harmonic grammar of 18th-century style, are you really ready to understand how to write a melody that can articulate the harmony in that style. Because while what you say is certainly possible -- one can of course write a melody that implies a clear harmony, as Bach and others did -- doing so requires the knowledge of the complexity of the underlying harmonic language and the way melodies interact with it. I keep using the word "idiom" and "idiomatic," because a musical style really is like learning a language. (And 18th-century composers would often spend quite a few years learning this language because composing in it.)
Of course, if you just want to restrict your harmony to a few chords and simple modulations (maybe with some standard sequences), you can write simpler stuff and create effective melodies through strongly regulated harmonic tones. If you look at the stuff Mozart wrote when he was a kid, you can see how that works. But those pieces are often just strings of idioms with predetermined cadential motions and standard phrase lengths. Not that they aren't good music -- but they're using a rather simplified "grammar."
I could go on, but honestly the best study I can recommend is to look at melodies from whatever genre/style you're trying to imitate. And, if possible, start with "simple" examples. If you were trying to learn 18th-century melodic/harmonic interactions and implications, I'd start with a detailed study of pieces such as from the Bach notebooks, or early Mozart pieces if you want to understand later 18th-century style. Observe how bass lines create cadences and underpin harmonic motion. Notice how melodies complement them. Spend a lot of time looking at two-voice counterpoint to see how it implies harmony without filling in a lot of chord notes. Forget Roman numerals and almost everything you may have learned about them, because they didn't exist in the 18th century and obscure a lot of how 18th-century music works harmonically. Instead, notice the intervals and rhythms used. Notice how long phrases are, how motives are spun out, when sequences occur (and what types). Couple this with the sorts of exercises and patterns discussed in the Sanguinetti book, learn to extemporize in the style at the keyboard, to fill in voices within given structures (like figured bass, two-voice skeletons, and partimenti), and then you may begin to get a sense of the knowledge an 18th-century composer was working with to write a melody that articulated harmony in a masterful way. One (unfortunately) cannot become Bach overnight. But, frankly, it's a lot easier to learn how to write melodies like Bach to first learn the principles of two-voice counterpoint and implications in that style than to start with melody alone. Once you understand the many constraints and restrictions that are created with how melodies and basslines have to interact to create coherent phrases, you can understand you to write a melody that implies harmony by itself.
But perhaps you're not looking for something quite so focused on a specific historical style. In that case, the "rules" for melody to articulate harmony generally become more diffuse in later music. Greater freedom of dissonance usage means less predictability in terms of what constitutes a "chord tone" vs. "non-chord tone" in a melody, which means accompaniment is more important in fleshing out the harmony that is implied by a melody.
For simpler styles, it's easier to summarize the rules for implying harmony in many pop melodies of today: generally put chord tones in stronger metric positions, and as you note, the root and third of a triad are often better at determining chords than the fifth in many cases. But to write an effective song melody, you probably would want to learn the harmonic patterns of today -- although most singers and even many pop song composers don't necessarily realize it, there are many stock patterns to create 4-bar or 8-bar phrases with standard harmonic rhythms. You can create variants of those, but often the melody "feels right" when it's generated to work with something like that.