Some history, mostly about Old Japanese:
Etymologically, で developed as onbin form of にて during Early Middle Japanese period. にて can still be found in formal, literary or archaic contexts in modern language.
In Old Japanese and Middle Japanese, voiced plosives and fricatives were prenasalized, so b, d, z and g were actually /mb/, /nd/, /nz/ and /ŋg/. So phonological development of で was: /nite/ → /nde/ → /de/.
nite was originally the -te form of defective verb n- "to be":
Attributive (called Adnominal by Frellesvig 2010): nə (→ modern no)
Continuative (called Infinitive by Frellesvig 2010, called Converb by Vovin 2020): ni
Gerund (called Subordinative Converb by Vovin 2020): nite
Vovin (2020, pages 474-475) about Subordinative Converb nite:
2.4.1.3 Subordinative Converb Form n-i-te
The subordinative converb form n-i-te is a rare form in Western Old Japanese. It is attested only in the Man'yōshū, where it occurs five times. N-i-te has only two functions: (1) copula in a nominal predicate, (2) marker of a location of an action or a state.
...
The subordinative converb n-i-te is attested only in Classical Ryukyuan (in Ryūka) (Hokama 1995: 508), and does not reveal itself in either Old Ryukyuan or modern dialects. Thus, it is certainly a loan from Classical Japanese. The absence of the n-i-te form in both Eastern Old Japanese and Ryukyuan suggests that this form is a result of an internal development in Central Japanese.
Frellesvig considers that usage of nə and ni as case particles etc. developed from forms of aforementioned copula n-. However Vovin (2020) did not speculate it.
Vovin (2020, pages 145-158) about Dative-Locative Case Marker -ni:
1.2.2.4 Dative-Locative Case Marker -ni:
The case marker ni has the following functions in the language of Classical Japanese prose: (1) dative case marker, (2) locative case marker, (3) agent marker in passive constructions, (4) directive case marker. It also has a special conjunctional usage connecting two clauses, and indicates either a reason or concession. In this last case, the case marker -ni follows the attributive form of a verb.
1.2.2.4.1 Dative Case Marker
In this function -ni is used after animate nouns only.
...
1.2.2.4.2 Locative Case Marker
As a locative case marker, -ni has both spatial and temporal meanings.
...
1.2.2.4.5 Agent Marker in Passive Constructions
In this function, as the following examples show, -ni marks animate nouns as agents in a passive construction. In Classical Japanese, both animate and inanimate nouns could be used as agents in passive construction (Vovin 2003: 326), but in Old Japanese inanimate nouns do not appear in this function yet. This may be due to the scarcity of Old Japanese texts in comparison to Classical Japanese texts, but overall this is unlikely: it appears that the passive construction is relatively new in Old Japanese, as only two examples are attested in the texts.
...
There is one example in Old Japanese when the case marker -ni marks an
agent in the sentence that includes the verb sayar- ‘be prevented,’ which is not marked by a passive morpheme, but has an inherent passive meaning
...
1.2.2.4.6 Directive Case Marker
As a directive case marker, -ni indicates the direction of movement, as in modern Japanese.
...
As a subvariety of this function, ni is used after the nominalized form of a verb and before a following verb that expresses the goal of a movement. Most often the verb following ni is a verb of movement, but not always, as the following example from KK 1 shows. In Classical Japanese and later periods the following verb is always the verb of movement.
...
1.2.2.4.7 Special Usage
The case marker -ni occurs frequently after the attributive form of verbs. In this function, -ni serves as a conjunction between two clauses, often with the meaning ‘and,’ ‘because,’ ‘since,’ ‘as’ or ‘when,’ and, more rarely, ‘but’ or ‘although.’ It is reasonable to believe that we are dealing here with a case marker ni rather than with the converb form n-i of the defective verb n- ‘be.’ The reason for this belief is mainly typological: in other ‘Altaic’ languages that are similar to Japanese structurally, the dative-locative case marker has exactly the same function when used after attributive forms of verbs.
...
There is no reliable external etymology for -ni. If Whitman is right in his assumption that all cases of OJ /ni/ are indeed otsu-rui *nï (Whitman 1985: 36–38), it is possible to speculate that OJ -ni < *-nəy, and that it is connected etymologically with Eastern Old Japanese locative -na (see section 1.2.2.6), which was already moribund in the eighth century.
Vovin (2020, pages 459-468) about Converb n-i:
2.4.1.1 Converb Form n-i
The converb form n-i ‘being’ is used in a variety of functions. It may occur after both nominals and verbs, the latter normally being in their nominalized or attributive forms.
(1) The converb n-i can be used as a copula in a nominal predicate
...
(2) The converb n-i is frequently used after nouns and adjectives for
adverbializations
...
(3) Another usage of n-i is after the quasi-postpositions tamɛ ‘for,’ and yuwe ‘because,’ ‘for the sake of’ (lit. ‘reason,’ ‘cause,’ ‘sake’), which are historically bound nouns. Only the construction yuwe n-i is attested with relatively high frequency (50 cases in the Man'yōshū), and is found in both Early and Late Western Old Japanese. The construction tamɛ n-i is very rare (only 8 cases in the whole Man'yōshū), and it is attested reliably only in Late Western Old Japanese.
...
(4) The converb n-i can be also followed by the verbs nar- ‘to become,’ se- ‘to do,’ and the adjective posi ‘be desirable. ...
...
The converb form n-i is attested in Eastern Old Japanese in the same functions as in Western Old Japanese with the exception of the constructions yuwe n-i and tamɛ n-i.
The converb n-i of the defective verb n- ‘to be’ is attested in Old Ryukyuan as well as in modern dialects, including Southern Ryukyuan.
Extended copula forms were in Old Japanese: ni ar- (formed from copula form ni and verb ar- "to exist"), and contracted nar- (← ni ar-). Non-contracted forms were used more frequently than contracted forms in Old Japanese. (Sources disagree about situation in Middle Japanese, but I can guess that usage of non-contracted ni ar- was decreasing in favor of contracted nar-.)
Frellesvig (2010, page 235) in chapter about Early Middle Japanese:
Ni ar- had the variant nite ar-, with ar- following the gerund instead of the infinitive. In the course of EMJ nite ar- became de ar-, which is the source of the cNJ copula da (cf. 12.2.2, 15.2, 16.2).