As digital transformation accelerates, coding competency has emerged as a foundational literacy across educational contexts. Simultaneously, concerns over ethical judgment in programming practices have grown, especially with the widespread use of generative AI tools (e.g., ChatGPT, Copilot) and open-source platforms (e.g., GitHub). This study investigates how university students' ethical judgment structures are shaped by their coding comprehension, open-source practice, and ethical awareness. Additionally, it examines how these factors relate to students' self-reported coding misconduct and their perceived legitimacy of open-source use. Using data from 224 undergraduates enrolled in digital technology courses, we applied structural equation modeling to test the hypothesized model. Findings indicate that coding comprehension significantly predicts ethical awareness, while open-source practice does not. Surprisingly, higher ethical awareness was associated with an increased likelihood of misconduct experience, suggesting a post hoc formation of ethical reflection or a cognitive-action discrepancy. Ethical awareness also significantly predicted the perceived illegitimacy of open-source use in coding tasks, but no interaction effect was found between open-source practice and ethical awareness. These results highlight the complex, dynamic nature of ethical judgment in digital learning environments. The study provides empirical grounding for designing ethics education that integrates technical understanding with reflective learning, emphasizing post-behavioral ethics development in coding contexts.